Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ PHP NEWS
incremental flush). (David Carlier)
. Fixed bug GH-22395 (base_convert() outputs at most 64 characters).
(Weilin Du)
. Fixed integer overflow in getimagesize() and getimagesizefromstring() when
parsing an IFF chunk with a size of INT_MAX. (David Carlier, Weilin Du)

02 Jul 2026, PHP 8.4.23

Expand Down
3 changes: 3 additions & 0 deletions ext/standard/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,9 @@ static struct gfxinfo *php_handle_iff(php_stream * stream)
return NULL;
}
if ((size & 1) == 1) {
if (size == INT_MAX) {
return NULL;
}
size++;
}
if (chunkId == 0x424d4844) { /* BMHD chunk */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
getimagesizefromstring() IFF chunk size integer overflow (GH-getimagesize_oflow)
--CREDITS--
Alexandre Daubois
--FILE--
<?php
// IFF/ILBM with a chunk size of INT_MAX (0x7fffffff), an odd value.
// The parser rounds odd chunk sizes up to even via size++, which overflowed
// when size == INT_MAX. It must be handled gracefully rather than triggering UB.
$payload = "FORM" . "\x00\x00\x00\x00" . "ILBM" . "ABCD" . "\x7f\xff\xff\xff";
var_dump(getimagesizefromstring($payload));

// getimagesize() shares the same IFF parser through the file path.
$file = __DIR__ . "/getimagesizefromstring_iff_overflow.iff";
file_put_contents($file, $payload);
var_dump(getimagesize($file));
?>
--CLEAN--
<?php
@unlink(__DIR__ . "/getimagesizefromstring_iff_overflow.iff");
?>
--EXPECT--
bool(false)
bool(false)
Loading