Repository navigation
Conversation
png_read_start_row allocated big_row_buf with png_calloc only for interlaced images, and with plain png_malloc otherwise. For a non-interlaced read, png_read_IDAT_data does not always account for every byte of the padded row_bytes allocation, so the unfilled tail could reach filter and transform code uninitialized. Fixes an MSan use-of-uninitialized-value in png_read_filter_row_paeth_1byte_pixel reported by OSS-Fuzz (https://issues.oss-fuzz.com/issues/553267077, now public past its 90-day disclosure deadline). The same uninitialized buffer is also reachable from png_do_expand and png_do_expand_palette depending on color type; this change fixes all three call sites, confirmed with the standard PngSuite images (basn0g01/08, basn3p01/02/04/08) built against libpng_readapi_fuzzer under MemorySanitizer -- all previously crashing inputs now run clean, while their interlaced counterparts (which already used png_calloc) were unaffected either way. This appears to be a long-standing issue rather than a recent regression in big_row_buf's own allocation; it was likely only newly reachable through this fuzz target after 905e1f8 corrected how libpng_readapi_fuzzer.cc registers PNG_TRANSFORM_* flags.
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.
Summary
png_read_start_rowallocatesbig_row_bufwithpng_calloconly forinterlaced images, and with a plain
png_mallocotherwise:For a non-interlaced read, the row isn't always fully overwritten before
filter/transform code reads it, so the uninitialized tail can leak into
the decoded output path. This fixes it by always zero-initializing the
buffer (matching what the interlaced branch already did), rather than
special-casing it.
Found via
OSS-Fuzz issue 553267077
(
libpng_readapi_fuzzer, MemorySanitizer use-of-uninitialized-value inpng_read_filter_row_paeth_1byte_pixel), now public past its 90-daydisclosure deadline.
While reproducing it locally I found the same uninitialized buffer is
also reachable from
png_do_expandandpng_do_expand_palettedepending on color type/bit depth — this one change fixes all three
call sites.
This looks like a long-standing issue rather than a recent regression
in the allocation itself. It was likely only newly reachable through
this specific fuzz target after 905e1f8 corrected how
libpng_readapi_fuzzer.ccregistersPNG_TRANSFORM_*flags (it hadpreviously been calling
png_set_scale_16/png_set_packing/png_set_expanddirectly in combination withpng_read_png(..., PNG_TRANSFORM_IDENTITY, ...), which the libpngmanual says not to do).
Testing
Built
libpng_readapi_fuzzerwith MemorySanitizer via this project'sown
contrib/oss-fuzz/build.shand ran the standard PngSuite imagesagainst it before and after this change:
basn0g01.pngpng_do_expandbasn0g08.pngpng_read_filter_row_paeth_1byte_pixelbasn3p01.pngpng_do_expand_palettebasn3p02.png,basn3p04.png,basn3p08.pngpng_do_expand_palettebasn0g02.png,basn0g04.pngibasn0g08.png,ibasn3p08.png(interlaced)All 10 inputs run with zero MemorySanitizer warnings after this change.
🤖 Generated with Claude Code