-
Notifications
You must be signed in to change notification settings - Fork 18k
compress/gzip: Reader unable to parse headers with long comments #14639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Bumping up milestone since #20083 provides good evidence that this is a real issue. |
Change https://golang.org/cl/53637 mentions this issue: |
Pushing to Go1.11 milestone... but I think a more general API for resource limitation might be the better approach. See #20169 for some discussion. |
@dsnet This is still an issue. Did it go under? |
Running the snippet on Go1.15 clearly shows it's still an issue. Huh, apparently I had a fix for this that I never submitted: https://golang.org/cl/53637 |
@dsnet Okay, any chance you can push that forward? I am using For anyone else having that issue: a pragmatic solution might be to copy |
Having reviewed my CL, the reason I didn't push it through is because of concerns with this feature being an trivial avenue for denial-of-service attack where a malicious GZIP file could cause a server to allocate arbitrary amounts of memory. We have several options:
var zr gzip.Reader
zr.MaxFieldSize(math.MaxInt32)
if err := zr.Reset(r); err != nil {
... // handle err
}
... // make use of zr.Header.Comment Since this would probably require an API change, I'm adding the NeedDecision label. |
Using
go1.6
RFC 1952 for gzip does not specify a length for the comment and name fields.
The current implementation is inconsistent:
gzip.Writer
permits the writing of any length comment/name string ingzip.Header
.gzip.Reader
fails to read any comment/name string ingzip.Header
longer than 511 bytes.Playground example: https://play.golang.org/p/Zvjf8Q7jXe
Change 512 to 511 in the example, and it works again.
This causes issues reading gzip files produced by GZinga, which produces syntactically valid gzip files, but abuses the comment field to store meta data.
Update: I have no intention of fixing this unless there is someone who needs this functionality. Whatever fix we do will need to be careful that we don't introduce a potential vector for DOS attacks since gzip is a common
Transfer-Encoding
in HTTP. We don't want an infinitely long comment to cause a server to allocate an infinite amount of memory.The text was updated successfully, but these errors were encountered: