]> Cypherpunks repositories - gostls13.git/commit
compress/flate: make library RFC1951 compliant
authorJoe Tsai <joetsai@digital-static.net>
Thu, 11 Jun 2015 23:33:52 +0000 (16:33 -0700)
committerNigel Tao <nigeltao@golang.org>
Wed, 17 Jun 2015 03:21:49 +0000 (03:21 +0000)
commitb03129aa2758a337823071ffda37e49da5a814d0
treee6c677347d1272ccd6f144d769e6928f814e378f
parent10076b55eccebadbaceacf946ae705fa40de52b3
compress/flate: make library RFC1951 compliant

Corrected several issues:
 * RFC1951 section 3.2.7 dictates that it is okay for the HDist tree to have a
single code of zero bits. Furthermore, the behavior of the C zlib library
permits empty trees even when there are more than one codes.
 * RFC1951 section 3.2.5 shows that HLit codes 286 and 287 are invalid. Thus,
Go's implementation should choke on inputs using these codes.
 * RFC1951 section 3.2.5 and 3.2.7 are ambiguous about whether the number of
HDist codes can be greater than 30. The C zlib library (which is the canonical
reference implementation) performs this check here:
https://github.com/madler/zlib/blob/62d6112a7981ad7c34f3b43cffdf00d4662a4f25/inflate.c#L906

In addition, a number of test cases were added to the unit tests that exercises
these edge cases. The test cases listed in TestStreams will either fail or
succeed in a manner matching the behaviour of the C zlib version. Given that the
C zlib implementation is the reference for the world, Go's implementation should
match C zlib behaviour.

Fixes #11030

Change-Id: Ic24e4e40ce5832c7e1930249246e86d34bfedaa6
Reviewed-on: https://go-review.googlesource.com/11000
Reviewed-by: Nigel Tao <nigeltao@golang.org>
src/compress/flate/flate_test.go
src/compress/flate/gen.go
src/compress/flate/huffman_bit_writer.go
src/compress/flate/huffman_code.go
src/compress/flate/inflate.go