esell / deb-simple

A lightweight, bare-bones apt repository server
MIT License
238 stars 17 forks source link

Handle trailing whitespace in control files #13

Closed amoghe closed 8 years ago

amoghe commented 8 years ago

In func inspectPackageControl , we return the args via return controlBuf.String(), nil. However, I've encountered control files that have a trailing newline. The return string from this func is used to create the 'Packages.gz' file, and if the return string has newlines, these make their way into the Packages.gz file but apt clients (esp. Ubuntu 12.04) can get unhappy about stray newlines.

The fix is to trim trailing blank chars from the controlBuf.String()

esell commented 8 years ago

Just pushed a fix if you want to give it a go.

amoghe commented 8 years ago

I looked at the patch, and I don't think that would fix it.

As I mentioned earlier, the string returned by inspectPackageControl can contain trailing newlines if the pkg control file has trailing newlines. This string gets written directly to the buffer thats being built to output the Packages.gz file. Hence, that file can end up containing things like:

The offending code:

tempCtlData, err := inspectPackage(debPath)
if err != nil {
    return err
}
packBuf.WriteString(tempCtlData) // <-- If tempCtlData contains newlines, they get written through
Package: foo
SomeStuff: blahblah
\n
\n <-- !!! these newlines are BAD. they "leak" from tempCtlData
\n
MD5sum: BADBADSUM
SHA1: SUMSUM
\n <-- these newlines are VALID separators
\n
Package: bar
SomeStuff: blahblah
... and so on and so forth...
amoghe commented 8 years ago

A possible fix is:

@@ -152,7 +157,7 @@ func inspectPackageControl(filename bytes.Buffer) (string, error) {
                case tar.TypeReg:
                        if name == "./control" {
                                io.Copy(&controlBuf, tarReader)
-                               return controlBuf.String(), nil
+                               return strings.TrimRight(controlBuf.String(), "\n") + "\n", nil
                        }
esell commented 8 years ago

My bad, I misunderstood what the issue was and thought it was just newlines at the end of the file. Let me play around with your suggestion and see what happens.

It's strange that this is an issue because we're just doing an io.Copy of the original control file. I wonder why the issue is not seen with other repo solutions? Either way we'll figure it out :)

esell commented 8 years ago

Just merged in https://github.com/esell/deb-simple/pull/15 if you want to give it a go again...

esell commented 8 years ago

gonna go ahead and close this guy, feel free to re-open it if the previous PR didn't fix your issue.