[php-src] PR #25725: Fix heap-buffer-overflow read in exif_scan_thumbnail()
| From: | Perennos | Date: | Wed, 25 Nov 2026 02:11:34 +0000 |
| Subject: | [php-src] PR #25725: Fix heap-buffer-overflow read in exif_scan_thumbnail() | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-40983@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/25725
Author: Perennos
Fixes the heap-buffer-overflow (READ of size 1) in
exif_scan_thumbnail() reported by
OSS-Fuzz: https://issues.oss-fuzz.com/issues/579569397
exif_scan_thumbnail() previously checked pos >= Thumbnail.size before
reading the 2-byte JPEG segment length via php_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. Requiring pos + 1 < size
ensures 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 exercises
exif_scan_thumbnail(). It reproduces on PHP-8.4.
Testing (ASan build, USE_ZEND_ALLOC=0, --disable-all --enable-exif
--enable-debug):
- Added 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).
- Before the fix: ASan reports heap-buffer-overflow ... READ of size 1 in
php_jpg_get16 called from exif_scan_thumbnail.
- After the fix: the test passes, and make test TESTS=ext/exif passes 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.