Skip to content

Commit 7a6a763

Browse files
committed
Fix OSS-Fuzz #442954659: Crash in exif_scan_HEIF_header
1 parent eba4140 commit 7a6a763

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

ext/exif/exif.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4308,7 +4308,7 @@ static int exif_isobmff_parse_box(unsigned char *buf, isobmff_box_type *box)
43084308
static void exif_isobmff_parse_meta(unsigned char *data, unsigned char *end, isobmff_item_pos_type *pos)
43094309
{
43104310
isobmff_box_type box, item;
4311-
unsigned char *box_offset, *p;
4311+
unsigned char *p;
43124312
int header_size, exif_id = -1, version, item_count, i;
43134313

43144314
size_t remain;
@@ -4323,7 +4323,8 @@ static void exif_isobmff_parse_meta(unsigned char *data, unsigned char *end, iso
43234323
p += (n); \
43244324
} while (0)
43254325

4326-
for (box_offset = data + 4; box_offset < end - 16; box_offset += box.size) {
4326+
unsigned char *box_offset = data + 4;
4327+
while (box_offset < end - 16) {
43274328
header_size = exif_isobmff_parse_box(box_offset, &box);
43284329
if (box.size < header_size) {
43294330
return;
@@ -4376,6 +4377,11 @@ static void exif_isobmff_parse_meta(unsigned char *data, unsigned char *end, iso
43764377
}
43774378
break;
43784379
}
4380+
4381+
if (end - 16 - box_offset <= box.size) {
4382+
break;
4383+
}
4384+
box_offset += box.size;
43794385
}
43804386

43814387
#undef ADVANCE
1023 Bytes
Binary file not shown.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
OSS-Fuzz #442954659 (Crash in exif_scan_HEIF_header)
3+
--EXTENSIONS--
4+
exif
5+
--FILE--
6+
<?php
7+
exif_read_data(__DIR__."/input");
8+
?>
9+
--EXPECTF--
10+
Warning: exif_read_data(%s): Invalid HEIF file in %s on line %d

0 commit comments

Comments
 (0)