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)