Fix integer overflow in ICC tag offset and parser bounds checks (OSS-Fuzz 501676165)#403
Merged
Merged
Conversation
…Fuzz 501676165) On 32-bit platforms, size_t is 32-bit (uint32_t). When parsing ICC profiles in IccHelper::readIccColorGamut, tag offsets and sizes read from malformed profiles can cause additive integer wrap-around (e.g. kICCIdentifierSize + cicp_offset + cicp_size <= icc_size wrapping around). This bypasses bounds checks and causes out-of-bounds heap memory reads. This change replaces additive bounds checks with subtraction-based checks across icc.cpp, jpegrutils.cpp, and gainmapmetadata.cpp, adds tag table size validation, and adds a regression test in icchelper_test.cpp. BUG=501676165
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
On 32-bit platforms (e.g.
libfuzzer_asan_i386),size_tis 32-bit (uint32_t). When parsing ICC profiles inIccHelper::readIccColorGamut, tag offsets and sizes read from malformed profiles can cause additive integer wrap-around (e.g.,kICCIdentifierSize + cicp_offset + cicp_size <= icc_sizewrapping around to11 <= icc_size). This bypasses bounds checks and causes out-of-bounds heap memory reads (Heap-buffer-overflow READ 1), reported in OSS-Fuzz issue 501676165.Fix
icc.cpp,jpegrutils.cpp, andgainmapmetadata.cpp(offset <= profile_size && size <= profile_size - offset).tag_count > max_tags) to prevent tag table indexing wrap-around.iccIntegerOverflowOffsetintests/icchelper_test.cppverifying safe handling of wrapping tag offsets.Fixes OSS-Fuzz 501676165.
Original Piper CL: cl/949044592.