Repository navigation
Conversation
The 2 byte segment length was read after only checking that one byte remained in the thumbnail buffer, so a thumbnail ending right after a JPEG marker read one byte past the end. Found by OSS-Fuzz (issue 579569397).
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.
Fixes the heap-buffer-overflow (READ of size 1) in
exif_scan_thumbnail()reported by OSS-Fuzz: https://issues.oss-fuzz.com/issues/579569397exif_scan_thumbnail()previously checkedpos >= Thumbnail.sizebefore reading the 2-byte JPEG segment length viaphp_jpg_get16(data + pos). When a marker ends with only one byte remaining in the thumbnail buffer (pos == size - 1), reading the second length byte advances one byte past the buffer. Requiringpos + 1 < sizeensures both bytes are in bounds and returns false otherwise.This pre-existing issue was exposed after #24722 updated the fuzzer to call
exif_thumbnail()with width/height arguments, which exercisesexif_scan_thumbnail(). It reproduces on PHP-8.4.Testing (ASan build,
USE_ZEND_ALLOC=0,--disable-all --enable-exif --enable-debug):ext/exif/tests/exif_scan_thumbnail_truncated_marker.phpt, which constructs a TIFF with a 5-byte truncated JPEG thumbnail (FF D8 FF E0 00).heap-buffer-overflow ... READ of size 1inphp_jpg_get16called fromexif_scan_thumbnail.make test TESTS=ext/exifpasses in a standard run (96 passed, 0 failed, 4 skipped out of 100 tests).Targeted at PHP-8.4 as the lowest branch with active bug-fix support. No NEWS entry included; happy to add one if needed.
AI-assisted: drafted with an AI coding assistant; reproduced and tested locally before submitting.