Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 67b74b2

Browse files
committed
exif/heic: Avoid overflow when adding box size and checking against file size
We change the order of operations such that the file size check cannot overflow in the for loop. This prevents infinite loops. We also add an overflow check at the end of the loop body to prevent the addition of offset and box.size from overflowing.
1 parent 389691a commit 67b74b2

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

‎ext/exif/exif.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4388,7 +4388,7 @@ static bool exif_scan_HEIF_header(image_info_type *ImageInfo, unsigned char *buf
43884388
bool ret = false;
43894389

43904390
pos.size = 0;
4391-
for (offset = php_ifd_get32u(buf, 1); ImageInfo->FileSize >offset+16; offset += box.size) {
4391+
for (offset = php_ifd_get32u(buf, 1); ImageInfo->FileSize -16>offset; offset += box.size) {
43924392
if ((php_stream_seek(ImageInfo->infile, offset, SEEK_SET) < 0) ||
43934393
(exif_read_from_stream_file_looped(ImageInfo->infile, (char*)buf, 16) != 16)) {
43944394
break;
@@ -4425,6 +4425,9 @@ static bool exif_scan_HEIF_header(image_info_type *ImageInfo, unsigned char *buf
44254425
efree(data);
44264426
break;
44274427
}
4428+
if (offset + box.size < offset) {
4429+
break;
4430+
}
44284431
}
44294432

44304433
return ret;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /