Closed shutton closed 2 years ago
I've thrown together a patch for to put in debug_asserts
for the actual invariants that the code is working under:
The trace of running decoding with those suggest that the comparison itself relies on an incorrect assumption. Since it uses ==
it relies on self.next_code <= self.code_buffer.max_code()
but that doesn't hold. When we reach 12-bits then the code buffer does not get larger and max_code()
remains at 4095. At the same time next_code
will advance to 4096, and never beyond in the sequential code path, a code that will never be created and thus works correctly with the rest of the logic.
But when that is the exact moment that we enter a burst, as is the case with the provided file, then it will advance next_code
beyond that and not notice that the maximum code has been reached. An easy fix would be to adjust the condition:
if potential_code >= self.code_buffer.max_code() - Code::from(self.is_tiff) {
I'll measure if that leads to too much of a performance loss due to executing less of the simple code reconstruction.
This addresses a problem in the GIF parser detected during fuzzing of a crate that utilizes
image-rs
. The issue can be reproduced using this short test program and the attached file (too large to include in the source -- unzip first).5220731288420352.gif.zip
After the fix, loading the malformed image produces a usable
Err
result: