Repository navigation
Conversation
The three fuzz targets decode with `Transformations::IDENTITY`, the default of `Decoder::new` and `Decoder::new_with_limits`. Under `IDENTITY`, `create_transform_fn` returns `copy_row` for every image. The other row transformations in `src/decoder/transform` are selected only with `EXPAND`, `ALPHA` or `STRIP_16`, so none of the targets reaches them: over `fuzz/corpus/decode`, the `decode` target covers 0 of 69 lines of `transform/palette.rs` and 19 of 122 lines of `transform.rs`. The panic that image-rs#682 fixed was in the palette expansion. For each nonempty input, the last byte now selects one of the six distinct combinations of the three flags (`ALPHA` implies `EXPAND`), and `decode` passes the whole input to the decoder one time, so the corpus needs no conversion. The target takes the buffer size from `output_buffer_size`, because the expanded output can be larger than `raw_bytes`. Over the same corpus it covers 54 of 69 and 112 of 122 lines.
rowanz
force-pushed
the
fuzz/decode-with-transformations
branch
from
November 22, 2026 03:31
c1e5109 to
3fcf211
Compare
decode under every output transformationdecode target
rowanz
marked this pull request as ready for review
November 22, 2026 03:45
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.
Problem
The three fuzz targets (
decode,buf_independentandroundtrip) decode withTransformations::IDENTITY, the default ofDecoder::newandDecoder::new_with_limits. UnderIDENTITY,create_transform_fnreturnscopy_rowfor every image. The other row transformations insrc/decoder/transform(palette,tRNSand bit-depth expansion, andSTRIP_16) are selected only withEXPAND,ALPHAorSTRIP_16, so none of the three targets reaches them. They are the targets that the OSS-Fuzz project builds (projects/image-png/build.sh), which CIFuzz uses too.imagedecodes withEXPAND.The out-of-bounds panic that #682 fixed was in the palette expansion (
transform/palette.rs), which these targets cannot reach.Repro
Line coverage of the
decodetarget over the committed corpus (fuzz/corpus/decode, 1,210 files), on master (b2f10c6):src/decoder/transform/palette.rssrc/decoder/transform.rssrc/decoder/mod.rsI also ran the target in one campaign for each checkout: 132 libFuzzer invocations (88 without a sanitizer, 44 with AddressSanitizer), each with a budget of 25 minutes, seeded with
fuzz/corpus/decodeand the PNG files undertests/of at most 16,384 bytes:transform/palette.rs:74)A separate campaign with the first version of this PR, which decoded each input six times, found that panic on 0.18.1 in 25 of 132 invocations.
Fix
For each nonempty input, the last byte selects one of the six distinct combinations of
EXPAND,ALPHAandSTRIP_16(ALPHAimpliesEXPAND), and the target passes the whole input to the decoder one time. The corpus needs no conversion. The target takes the buffer size fromoutput_buffer_size, because the expanded output can be larger thanraw_bytes; the 5 MB cap on that buffer stays.A complete PNG file ends with the byte
0x82of theIENDCRC, which selectsALPHA. The corpora hold all six combinations. In the order of the array in the target, OSS-Fuzz's public corpus of the target (7,993 files) has 2,855, 801, 983, 1,013, 958 and 1,383 files for them, andfuzz/corpus/decodehas 467, 96, 100, 253, 217 and 77. To replay a saved input, use its bytes unchanged.On an aarch64 machine with AddressSanitizer, one pass over that public corpus (
decode -runs=0) took about as long as on master. The times are the median of three passes, andcovandftare libFuzzer's numbers at the end of the pass:covftThe last row is that first version of this PR, which decoded each input under all six combinations. Over that corpus it covers the same lines of
src/as this version (2,401 of 4,732 inllvm-cov report). Overfuzz/corpus/decodeit covers 66 of the 69 lines ofpalette.rs, where this version covers 54. In one comparison on master (24 invocations of each target with a five-minute budget, no sanitizer, the seeds of the campaigns above), the pooled corpora covered 67 of those 69 lines with this version and 66 with six decodes.I measured the first version because of its CIFuzz run (https://github.com/image-rs/image-png/actions/runs/44976672754), which got through the corpus at 68 executions per second. The CIFuzz run of this version (https://github.com/image-rs/image-png/actions/runs/44981025503) had the same corpus (7,993 files, 75,663,893 bytes) and got through it at 194 executions per second. With a 120-second budget, the six-decode run recorded 8,937 total executions and this version recorded 27,121. The nine CIFuzz runs before these two that ran
decodegot 194 to 486 executions per second, on other commits and on the corpus of other days.