std/brotli: document the uninitialized ring buffer tail reads

libbrotlienc can read the uninitialized tail of a ring buffer that it grew
after a short first write, and the Wuffs encoder reads the corresponding
workbuf bytes, so both outputs can depend on memory contents (and agree
when the memory does). The fuzzer reruns a mismatch with zeroed memory for
both encoders and counts it as uninit_tail when the outputs then agree and
Wuffs' output decodes.
This commit is contained in:
Claude committed 2026-10-27 16:47:03 +00:00
1 parent 73de2fe182
commit 8dcecc67af
2 files changed
+72 -3

No files matched your search

+10
View File
@@ -674,6 +674,16 @@ on, which is what libbrotlienc does once `ProcessMetadata` sets `next_out_` to
`test_mimic_brotli_encode_metadata_stale_pointer` test in
`test/c/std/brotli.c` shows it at quality 1.
Neither encoder's output is fully determined by its input and parameters.
libbrotlienc's `RingBufferWrite` allocates only the first write's bytes when
that write is shorter than the ring buffer's tail, and when it later grows the
buffer it copies them but leaves the tail (the copy of the buffer's start,
past its end) uninitialized. Match finding near the ring buffer's end can read
those bytes, so the output can depend on what that `malloc`'d memory held. The
Wuffs encoder reads the corresponding `workbuf` bytes, which the caller need
not initialize. Given the same memory contents (e.g. zeroed), both produce
the same bytes, and both outputs decode correctly.
### Encoder Large Window