From 025ea9b55c14c371c93ee48cd056a9bc276c13c1 Mon Sep 17 00:00:00 2001 From: Perennos <333385283+Perennos@users.noreply.github.com> Date: Wed, 25 Nov 2026 02:10:26 +0000 Subject: [PATCH] Fix heap-buffer-overflow read in exif_scan_thumbnail() 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). --- ext/exif/exif.c | 4 +-- .../exif_scan_thumbnail_truncated_marker.phpt | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 ext/exif/tests/exif_scan_thumbnail_truncated_marker.phpt diff --git a/ext/exif/exif.c b/ext/exif/exif.c index a72acb4f2c50..73e71b5d788a 100644 --- a/ext/exif/exif.c +++ b/ext/exif/exif.c @@ -4031,8 +4031,8 @@ static bool exif_scan_thumbnail(image_info_type *ImageInfo) if (c == 0xFF) return false; marker = c; - if (pos>=ImageInfo->Thumbnail.size) - return false; + if (pos+1>=ImageInfo->Thumbnail.size) + return false; /* the 2 byte length field must fit */ length = php_jpg_get16(data+pos); if (length > ImageInfo->Thumbnail.size || pos >= ImageInfo->Thumbnail.size - length) { return false; diff --git a/ext/exif/tests/exif_scan_thumbnail_truncated_marker.phpt b/ext/exif/tests/exif_scan_thumbnail_truncated_marker.phpt new file mode 100644 index 000000000000..bcb262a3c0f9 --- /dev/null +++ b/ext/exif/tests/exif_scan_thumbnail_truncated_marker.phpt @@ -0,0 +1,30 @@ +--TEST-- +exif_thumbnail(): truncated JPEG marker segment at the end of the thumbnail +--EXTENSIONS-- +exif +--FILE-- + +--EXPECT-- +int(5) +int(0) +int(0)