Skip to content

Commit f08491b

Browse files
committed
ext/standard: getimagesize()/getimagesizefromstring() overflow.
close phpGH-22574
1 parent 21bf7f6 commit f08491b

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ PHP NEWS
7070
incremental flush). (David Carlier)
7171
. Fixed bug GH-22395 (base_convert() outputs at most 64 characters).
7272
(Weilin Du)
73+
. Fixed integer overflow in getimagesize() and getimagesizefromstring()
74+
when parsing an IFF chunk with a size of INT_MAX. (David Carlier, Weilin Du)
7375

7476
- Zip:
7577
. Fixed bug GH-21705 (ZipArchive::getFromIndex() ignores

ext/standard/image.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,9 @@ static struct gfxinfo *php_handle_iff(php_stream * stream)
875875
return NULL;
876876
}
877877
if ((size & 1) == 1) {
878+
if (size == INT_MAX) {
879+
return NULL;
880+
}
878881
size++;
879882
}
880883
if (chunkId == 0x424d4844) { /* BMHD chunk */
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
getimagesizefromstring() IFF chunk size integer overflow (GH-getimagesize_oflow)
3+
--CREDITS--
4+
Alexandre Daubois
5+
--FILE--
6+
<?php
7+
// IFF/ILBM with a chunk size of INT_MAX (0x7fffffff), an odd value.
8+
// The parser rounds odd chunk sizes up to even via size++, which overflowed
9+
// when size == INT_MAX. It must be handled gracefully rather than triggering UB.
10+
$payload = "FORM" . "\x00\x00\x00\x00" . "ILBM" . "ABCD" . "\x7f\xff\xff\xff";
11+
var_dump(getimagesizefromstring($payload));
12+
13+
// getimagesize() shares the same IFF parser through the file path.
14+
$file = __DIR__ . "/getimagesizefromstring_iff_overflow.iff";
15+
file_put_contents($file, $payload);
16+
var_dump(getimagesize($file));
17+
?>
18+
--CLEAN--
19+
<?php
20+
@unlink(__DIR__ . "/getimagesizefromstring_iff_overflow.iff");
21+
?>
22+
--EXPECT--
23+
bool(false)
24+
bool(false)

0 commit comments

Comments
 (0)