Repository navigation
Don't count filter bytes for empty Adam7 passes - #737
Open
Mrmaxmeier wants to merge 1 commit into
Open
Mrmaxmeier wants to merge 1 commit into
Mrmaxmeier wants to merge 1 commit into
Conversation
The byte count of an interlaced frame (`UnfilteringBuffer::start_frame`)
adds `raw_row_length_from_width(samples) * lines` for all 7 passes. For
a pass without samples (passes 2, 4 and 6 of an image 1 pixel wide, and
so on) `raw_row_length_from_width(0)` is 1, so one filter byte is
counted per line, although `Adam7Iterator` skips such passes and the
encoder writes no rows for them. The decoder then waits for image data
that does not exist:
* a zlib stream that ends right after the pixel data without a final block
(accepted for the non-interlaced image) is rejected with
`CorruptFlateStream { InsufficientInput }`, and
* corrupt trailing zlib data after the pixel data is decompressed and
reported, except when the reader hits an `UnexpectedEof` first and the
frame is completed from the readable rows (the `buf_independent` fuzzer:
results differ between a whole-slice reader and an intermittent-EOF
reader).
Skip passes without samples. Valid images decode unchanged.
Assisted-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi,
I ran into something with the
buf_independentfuzzer recently. The minimal reproducer is a 1x1 interlacedimage whose zlib stream ends right after the pixel data, without a final block. Depending on how the
input is split into reads, it either decodes or fails:
The same image without interlacing decodes fine with all three readers.
The
Readercomputes the number of image data bytes in a frame up front. For interlaced framesthat's a sum over the 7 Adam7 passes:
image-png/src/decoder/mod.rs
Lines 374 to 386 in b2f10c6
Some passes can be empty, e.g. passes 2, 4 and 6 of a 1-pixel-wide image. For those,
raw_row_length_from_width(0)is 1, so the sum counts a filter byte for each of their lines. Butan empty pass has no data at all
(PNG 1.2, 2.6):
and
Adam7Iteratoralready skips them.So for the 1x1 image the decoder expects 5 bytes instead of 2 and keeps reading the zlib stream after
the last row. If the stream ends properly, that's harmless. Here it doesn't, so the decoder runs out
of input and fails, unless the reader reports an
UnexpectedEoffirst: thennext_raw_interlaced_rowfinishes with the row it already has, and the frame completes.This PR skips empty passes when computing the frame size. Valid images decode as before, and the
reproducer decodes with all three readers.
Thanks!