Skip to content

Commit 2c4ae7b

Browse files
committed
Fix OSS-Fuzz #442954659: zero-size box in HEIF file causes infinite loop
If the box size is 0, the loop can't progress.
1 parent 3e9caf5 commit 2c4ae7b

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

ext/exif/exif.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4312,6 +4312,9 @@ static void exif_isobmff_parse_meta(unsigned char *data, unsigned char *end, iso
43124312

43134313
for (box_offset = data + 4; box_offset + 16 < end; box_offset += box.size) {
43144314
header_size = exif_isobmff_parse_box(box_offset, &box);
4315+
if (box.size < header_size) {
4316+
return;
4317+
}
43154318
if (box.type == FOURCC("iinf")) {
43164319
p = box_offset + header_size;
43174320
if (p >= end) {
@@ -4334,6 +4337,9 @@ static void exif_isobmff_parse_meta(unsigned char *data, unsigned char *end, iso
43344337
}
43354338
for (i = 0; i < item_count && p + 20 < end; i++) {
43364339
header_size = exif_isobmff_parse_box(p, &item);
4340+
if (item.size < header_size) {
4341+
return;
4342+
}
43374343
if (p + header_size + 12 >= end) {
43384344
return;
43394345
}
@@ -4396,6 +4402,9 @@ static bool exif_scan_HEIF_header(image_info_type *ImageInfo, unsigned char *buf
43964402
break;
43974403
}
43984404
box_header_size = exif_isobmff_parse_box(buf, &box);
4405+
if (box.size < box_header_size) {
4406+
break;
4407+
}
43994408
if (box.type == FOURCC("meta")) {
44004409
limit = box.size - box_header_size;
44014410
if (limit < 36) {
144 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 (zero-size box in HEIF file causes infinite loop)
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)