Skip to content

Commit 1baeae4

Browse files
committed
Fix bug #76423 - Int Overflow lead to Heap OverFlow in exif_thumbnail_extract of exif.c
1 parent fe3d53f commit 1baeae4

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

ext/exif/exif.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2545,7 +2545,10 @@ static void exif_thumbnail_extract(image_info_type *ImageInfo, char *offset, siz
25452545
return;
25462546
}
25472547
/* Check to make sure we are not going to go past the ExifLength */
2548-
if ((ImageInfo->Thumbnail.offset + ImageInfo->Thumbnail.size) > length) {
2548+
if (ImageInfo->Thumbnail.size > length
2549+
|| (ImageInfo->Thumbnail.offset + ImageInfo->Thumbnail.size) > length
2550+
|| ImageInfo->Thumbnail.offset > length - ImageInfo->Thumbnail.size
2551+
) {
25492552
EXIF_ERRLOG_THUMBEOF(ImageInfo)
25502553
return;
25512554
}

ext/exif/tests/bug76423.jpg

1.5 KB
Loading

ext/exif/tests/bug76423.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Bug #76423 (Int Overflow lead to Heap OverFlow in exif_thumbnail_extract of exif.c)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('exif')) die('skip exif extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
exif_read_data(__DIR__ . '/bug76423.jpg', 0, true, true);
10+
?>
11+
===DONE===
12+
--EXPECTF--
13+
14+
Warning: exif_read_data(%s.jpg): Thumbnail goes IFD boundary or end of file reached in %s on line %d
15+
16+
Warning: exif_read_data(%s.jpg): File structure corrupted in %s on line %d
17+
18+
Warning: exif_read_data(%s.jpg): Invalid JPEG file in %s on line %d
19+
===DONE===

0 commit comments

Comments
 (0)