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

+11 -8
View File
@@ -27008,14 +27008,17 @@ wuffs_deflate__decoder__init_huff(
v_i += 1;
}
if (v_remaining != 0) {
if ((a_which == 1) &&
(v_counts[1] == 1) &&
(self->private_data.f_code_lengths[a_n_codes0] == 1) &&
((((uint32_t)(v_counts[0])) + a_n_codes0 + 1) == a_n_codes1)) {
self->private_impl.f_n_huffs_bits[1] = 1;
self->private_data.f_huffs[1][0] = (WUFFS_DEFLATE__DCODE_MAGIC_NUMBERS[0] | 1);
self->private_data.f_huffs[1][1] = (WUFFS_DEFLATE__DCODE_MAGIC_NUMBERS[31] | 1);
return wuffs_base__make_status(NULL);
if ((a_which == 1) && (v_counts[1] == 1) && ((((uint32_t)(v_counts[0])) + a_n_codes0 + 1) == a_n_codes1)) {
v_i = 0;
while (v_i <= 29) {
if (self->private_data.f_code_lengths[(a_n_codes0 + v_i)] == 1) {
self->private_impl.f_n_huffs_bits[1] = 1;
self->private_data.f_huffs[1][0] = (WUFFS_DEFLATE__DCODE_MAGIC_NUMBERS[v_i] | 1);
self->private_data.f_huffs[1][1] = (WUFFS_DEFLATE__DCODE_MAGIC_NUMBERS[31] | 1);
return wuffs_base__make_status(NULL);
}
v_i += 1;
}
}
return wuffs_base__make_status(wuffs_deflate__error__bad_huffman_code_under_subscribed);
}