Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ext/exif/exif.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
30 changes: 30 additions & 0 deletions ext/exif/tests/exif_scan_thumbnail_truncated_marker.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--TEST--
exif_thumbnail(): truncated JPEG marker segment at the end of the thumbnail
--EXTENSIONS--
exif
--FILE--
<?php
// Little-endian TIFF: empty IFD0, IFD1 pointing at a 5 byte thumbnail
// (FF D8 FF E0 00) at the very end of the data. The marker length field
// of the APP0 segment would start at the last byte, so reading its two
// bytes must not run past the thumbnail buffer.
$thumb = "\xFF\xD8\xFF\xE0\x00";
$tiff = "II*\x00" . pack("V", 8)
. pack("v", 0) . pack("V", 14)
. pack("v", 2)
. pack("vvVV", 0x0201, 4, 1, 44)
. pack("vvVV", 0x0202, 4, 1, strlen($thumb))
. pack("V", 0)
. $thumb;

$stream = fopen("php://memory", "w+");
fwrite($stream, $tiff);
rewind($stream);

var_dump(strlen(exif_thumbnail($stream, $width, $height, $type)));
var_dump($width, $height);
?>
--EXPECT--
int(5)
int(0)
int(0)
Loading