std/brotli: fix long zero runs in the fast Huffman tree encoding

build_and_store_huffman_tree_fast_generic indexed the 704-entry
ZERO_REPS and NON_ZERO_REPS tables with reps & 511, so a run of more
than 511 equal code lengths (e.g. unused command codes between 75 and
688 in a quality 2 metablock of more than 128 commands) was written
wrongly and the stream did not decode. Found by the differential
fuzzer (quality 2, lgwin 10).
This commit is contained in:
Claude committed 2026-10-27 14:20:18 +00:00
1 parent a856d133d9
commit dbd5a00715
3 files changed
+52 -4

No files matched your search

+2 -2
View File
@@ -85619,7 +85619,7 @@ wuffs_brotli__encoder__build_and_store_huffman_tree_fast_generic(
}
v_i += v_reps;
if (v_value == 0u) {
wuffs_brotli__encoder__write_bits(self, WUFFS_BROTLI__ZERO_REPS_DEPTH[(v_reps & 511u)], WUFFS_BROTLI__ZERO_REPS_BITS[(v_reps & 511u)], a_s);
wuffs_brotli__encoder__write_bits(self, WUFFS_BROTLI__ZERO_REPS_DEPTH[wuffs_base__u32__min(v_reps, 703u)], WUFFS_BROTLI__ZERO_REPS_BITS[wuffs_base__u32__min(v_reps, 703u)], a_s);
} else {
if (v_prev_value != v_value) {
wuffs_brotli__encoder__write_bits(self, WUFFS_BROTLI__CODE_LENGTH_DEPTH[(v_value & 15u)], WUFFS_BROTLI__CODE_LENGTH_BITS[(v_value & 15u)], a_s);
@@ -85632,7 +85632,7 @@ wuffs_brotli__encoder__build_and_store_huffman_tree_fast_generic(
}
} else {
v_reps -= 3u;
wuffs_brotli__encoder__write_bits(self, WUFFS_BROTLI__NON_ZERO_REPS_DEPTH[(v_reps & 511u)], WUFFS_BROTLI__NON_ZERO_REPS_BITS[(v_reps & 511u)], a_s);
wuffs_brotli__encoder__write_bits(self, WUFFS_BROTLI__NON_ZERO_REPS_DEPTH[wuffs_base__u32__min(v_reps, 703u)], WUFFS_BROTLI__NON_ZERO_REPS_BITS[wuffs_base__u32__min(v_reps, 703u)], a_s);
}
v_prev_value = v_value;
}