Skip to content

Commit 6a0da6d

Browse files
Oblivionsagendossche
authored andcommitted
Fix GH-20631: Integer underflow in exif HEIF parsing
When pos.size is less than 2, the subtraction pos.size - 2 causes an unsigned integer underflow, resulting in a ~4GB allocation attempt. Add minimum size check (pos.size >= 2) to prevent the underflow. Closes GH-20630.
1 parent aa82371 commit 6a0da6d

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.5.2
44

5+
- EXIF:
6+
. Fixed bug GH-20631 (Integer underflow in exif HEIF parsing
7+
when pos.size < 2). (Oblivionsage)
58

69
18 Dec 2025, PHP 8.5.1
710

ext/exif/exif.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4421,7 +4421,7 @@ static bool exif_scan_HEIF_header(image_info_type *ImageInfo, unsigned char *buf
44214421
if (exif_read_from_stream_file_looped(ImageInfo->infile, (char*)(data + remain), limit - remain) == limit - remain) {
44224422
exif_isobmff_parse_meta(data, data + limit, &pos);
44234423
}
4424-
if ((pos.size) &&
4424+
if ((pos.size >= 2) &&
44254425
(pos.size < ImageInfo->FileSize) &&
44264426
(ImageInfo->FileSize - pos.size >= pos.offset) &&
44274427
(php_stream_seek(ImageInfo->infile, pos.offset + 2, SEEK_SET) >= 0)) {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
HEIC iloc extent_length underflow
3+
--EXTENSIONS--
4+
exif
5+
--FILE--
6+
<?php
7+
// Read valid HEIC file and patch iloc extent_length to 1
8+
$data = file_get_contents(__DIR__."/image029.heic");
9+
$data = substr_replace($data, "\x00\x00\x00\x01", 0x4f8, 4);
10+
file_put_contents(__DIR__."/heic_iloc_underflow.heic", $data);
11+
var_dump(exif_read_data(__DIR__."/heic_iloc_underflow.heic"));
12+
?>
13+
--CLEAN--
14+
<?php
15+
@unlink(__DIR__."/heic_iloc_underflow.heic");
16+
?>
17+
--EXPECTF--
18+
Warning: exif_read_data(heic_iloc_underflow.heic): Invalid HEIF file in %s on line %d
19+
bool(false)

0 commit comments

Comments
 (0)