Fix std/deflate degenerate H-D Huffman table

RFC 1951 section 3.2.7. "Compression with dynamic Huffman codes
(BTYPE=10)" says, "If only one distance code is used, it is encoded
using one bit, not zero bits; in this case there is a single code length
of one, with one unused code."

I had previously mis-read that excerpt to also require that the sole
distance code was the shortest distance (code 0, a distance of 1).

Fixes #66
This commit is contained in:
Nigel Tao committed 2022-01-08 13:57:34 +11:00
1 parent dda01f1a77
commit f86c80e425
7 files changed
+75 -28

No files matched your search

@@ -2,8 +2,8 @@ Running degenerate-huffman-unused.deflate through script/print-bits.go and
adding commentary:
offset xoffset ASCII hex binary
000000 0x0000 . 0x05 0b_...._.101 Dynamic Huffman block, final
000000 0x0000 . 0x05 0b_0000_0... NumLCodes: 257
000000 0x0000 . 0x04 0b_...._.100 Dynamic Huffman block, non-final
000000 0x0000 . 0x04 0b_0000_0... NumLCodes: 257
000001 0x0001 . 0xC0 0b_...0_0000 NumDCodes: 1
000001 0x0001 . 0xC0 0b_110._.... NumCLCodeLengths: 18
000002 0x0002 ! 0x21 0b_...._...1
@@ -63,4 +63,7 @@ Apply H-L and H-D.
000013 0x000D . 0x89 0b_..0._.... lcode: 111 literal 'o'
000013 0x000D . 0x89 0b_.0.._.... lcode: 111 literal 'o'
000013 0x000D . 0x89 0b_1..._.... lcode: 256 end of block
000014 0x000E . 0x01 0b_...._...1
000014 0x000E . 0x1B 0b_...._...1
The second Dynamic Huffman block (the final one) continues after that, but this
commentary stops here.
@@ -1 +1 @@
foo
fooABCDABC
@@ -2,7 +2,7 @@
make deflate
blockDynamicHuffman (final) {
blockDynamicHuffman (nonFinal) {
huffman CodeLength {
1 00
2 01
@@ -19,9 +19,46 @@ blockDynamicHuffman (final) {
huffman Distance {
# Incomplete. There is no key/value pair whose value starts with "1".
#
# The sole key/value pair is also unused. (The one below is used.)
0 0
}
literal "foo"
endOfBlock
}
blockDynamicHuffman (final) {
huffman CodeLength {
0 00
1 01
2 100
3 101
17 110
18 111
}
huffman Literal/Length {
# 65='A', 66='B', 67='C', 68='D', 256=EOB, 257=Length3
65 100
66 101
67 110
68 111
256 00
257 01
}
huffman Distance {
# Incomplete. There is no key/value pair whose value starts with "1".
#
# The sole key/value pair is also used. (The one above is unused.)
#
# Per the second table in RFC 1951 section 3.2.5. "Compressed blocks
# (length and distance codes)", code 3 means a distance of 4.
3 0
}
literal "ABCD"
len 3 dist 4
endOfBlock
}