mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 16:47:28 +01:00
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:
1 parent
dda01f1a77
commit
f86c80e425
7 files changed
+75
-28
No files matched your search
@@ -628,17 +628,21 @@ pri func decoder.init_huff!(which: base.u32[..= 1], n_codes0: base.u32[..= 288],
|
||||
} endwhile
|
||||
if remaining <> 0 {
|
||||
// As a special case, allow a degenerate H-D Huffman table, with only
|
||||
// one 1-bit code, for the smallest possible distance.
|
||||
// one 1-bit code.
|
||||
if (args.which == 1) and (counts[1] == 1) and
|
||||
(this.code_lengths[args.n_codes0] == 1) and
|
||||
(((counts[0] as base.u32) + args.n_codes0 + 1) == args.n_codes1) {
|
||||
|
||||
this.n_huffs_bits[1] = 1
|
||||
this.huffs[1][0] = DCODE_MAGIC_NUMBERS[0] | 1
|
||||
this.huffs[1][1] = DCODE_MAGIC_NUMBERS[31] | 1
|
||||
return ok
|
||||
i = 0
|
||||
while i <= 29 {
|
||||
if this.code_lengths[args.n_codes0 + i] == 1 {
|
||||
this.n_huffs_bits[1] = 1
|
||||
this.huffs[1][0] = DCODE_MAGIC_NUMBERS[i] | 1
|
||||
this.huffs[1][1] = DCODE_MAGIC_NUMBERS[31] | 1
|
||||
return ok
|
||||
}
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
return "#bad Huffman code (under-subscribed)"
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user