Repository navigation
webp: forward max_alloc to image-webp memory limit - #3135
Open
tanjiroK-coder wants to merge 1 commit into
Open
tanjiroK-coder wants to merge 1 commit into
tanjiroK-coder wants to merge 1 commit into
Conversation
WebPDecoder did not override set_limits, so image-webp kept its default memory limit of usize::MAX. Metadata chunks (ICCP, EXIF, XMP) are allocated from their declared RIFF length before being read, which lets a tiny file request a ~4 GiB buffer regardless of Limits::max_alloc.
This branch has not been deployed
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.
WebPDecodernever overrodeset_limits, soLimits::max_allocwas never handed toimage_webp::WebPDecoder::set_memory_limitand the backend kept its default ofusize::MAX. image-webp indexes chunks by seeking past their declared RIFF length without comparing it to the stream length, andread_chunkthen sizes the ICCP/EXIF/XMP buffer withvec![0; len]before reading. A 64-byte extended WebP whose EXIF chunk declares0xFFFFFFF0bytes is enough:ImageReader::decodereads InHeader metadata eagerly, so withmax_allocat 1 MiB a counting allocator still saw a single 4294967280-byte request before the read hit EOF. That ignores the allocation cap callers set for untrusted input, and on 32-bit targets or hosts without overcommit an allocation that size aborts the process instead of returning an error. I found it while checking which decoders actually passmax_allocto their backend. PNG and TIFF do, WebP did not. The newset_limitskeeps the default support and dimension checks and forwards the cap, andMemoryLimitExceedednow maps toImageError::Limitsinstead of a generic decoding error. The added unit test uses that crafted file, fails on main with anIoError, and passes with the patch.cargo test,cargo fmt --checkand clippy with-D warningsare clean.