-
Notifications
You must be signed in to change notification settings - Fork 18.1k
compress/gzip: ignore trailing garbage data #47809
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
According to the documentation for
That probably explains why it says there's an invalid header. This lines up with what the Stack Overflow post suggests for Python. It may be that this is a bug, at least according to the Stack Overflow post, but I'm not sure. The link in that post re: the spec is broken. Looking at RFC 1952 which the package claims to follow, I don't see mention of this behavior. If you could provide a reference, that would be great. CC @dsnet via https://dev.golang.org/owners ? I guess also CC @mdempsky who is the secondary owner on a bunch of other compress packages. |
This is working as intended. The grammar in RFC 1952 does not allow for arbitrary junk at the end since a gzip file must be a series of valid members (section 2.2). It explicitly says that the "members simply appear one after another in the file, with no additional information before, between, or after them." This implies that it is not legal to have trailing junk. If you would like the ability to read a valid gzip member and specially handle non-gzip data after the member, then you can use the |
Just test this compress from gzip/7zip other decompress software it can decompress whole file succeed. @mknyszek I will looking for it when available. |
Regardless of what other popular software do, their behavior is clearly non-compliant with the specification. |
OK. Good to know that. It according RFC 1952 may be better. Thanks! |
It have any plan for support other compress/decompress algorithm? |
Can you explain what you mean? https://pkg.go.dev/compress shows the list of the compression formats that the Go standard library supports. The bar for a new format to be added is very high. It would have to be very popular format and someone needs to be willing to own it for the long term. The formats I can potentially see being added are Brotli and Zstandard, but I think their popularity still has a ways to go before it would considered for being added. Even then, there's still the question of who's going to maintain it. |
For extract question without this issue. I'm looking for LZ4 or ZStandard algorithms. It's any possible to become contributor with those compress packages? |
Any new formats to be added needs to be approved as a Go proposal. I doubt lz4 would ever be added. Zstandard is still in my opinion too young. |
And compare with other language (Like Java/Python). The also support rich compress algorithm on standard library supports. In my opinion. |
Both compressions already exist as pure Go libraries: So I think this is https://golang.org/doc/faq#x_in_std. |
Closing as this is working as intended Please file a proposals if you think something should be added to the stdlib |
Uh oh!
There was an error while loading. Please reload this page.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I trying to use go compress/gzip package to unzip this file.
But program pop me an error and then use gzip -d -k server.data I can get the actually data.
Then I looking into what is happened then I found this compress file include extra data.
Look back in go standard package code I did not see any code handle compress file extra data instead trying to use remaining data for next compress file (when MultipleStream is True).
Gzip file format documentation reference (from stackoverflow): https://stackoverflow.com/questions/4928560/how-can-i-work-with-gzip-files-which-contain-extra-data
Fully example code here: https://github.com/kunsonx/go-reproduce-data/blob/master/test-gzip-without-handle-extra-data.go
What did you expect to see?
No errors pop. compress file extra data handled.
What did you see instead?
error : "gzip: invalid header"
The text was updated successfully, but these errors were encountered: