Skip to content
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

zlib compression bytes are different from that of other languages #28594

Closed
arafangion opened this issue Nov 4, 2018 · 1 comment
Closed

Comments

@arafangion
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.11.1 darwin/amd64

Does this issue reproduce with the latest release?

Yes, it's right from https://golang.org/src/compress/zlib/example_test.go

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/johnchapman/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/johnchapman/src/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/xk/3nb32bq110j4rn52mqs3wf7w0000gq/T/go-build416559799=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Looked at https://golang.org/src/compress/zlib/example_test.go

And observed that byte 3 and up are different from most other languages.

What did you expect to see?

Bytes corresponding to the python3 example:

>>> import zlib
>>> a = zlib.compress(b'hello, world\n')
>>> b = [int(x) for x in a]
>>> print(b)
[120, 156, 203, 72, 205, 201, 201, 215, 81, 40, 207, 47, 202, 73, 225, 2, 0, 33, 231, 4, 147]

What did you see instead?

The Go code on line 22 of https://golang.org/src/compress/zlib/example_test.go
// Output: [120 156 202 72 205 201 201 215 81 40 207 47 202 73 225 2 4 0 0 255 255 33 231 4 147]

@dsnet
Copy link
Member

dsnet commented Nov 5, 2018

Closing as "working as intended".

The specifications for the compression formats are RFC 1950, RFC 1951, and RFC 1952. As specifications they do not specify what is considered "canonical" output, but only specify what is necessary for proper decompression. This implies that Go has the freedom to output whatever we want so long as it is decodable by a compliant decompressor.

The fact that other languages output the same bytes is likely because many implementations just wrap the C zlib library under the hood. On the other hand, the Go library actually implements compression with its own algorithms in pure Go.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants