File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -876,6 +876,9 @@ static struct php_gfxinfo *php_handle_iff(php_stream * stream)
876876 return NULL ;
877877 }
878878 if ((size & 1 ) == 1 ) {
879+ if (size == INT_MAX ) {
880+ return NULL ;
881+ }
879882 size ++ ;
880883 }
881884 if (chunkId == 0x424d4844 ) { /* BMHD chunk */
Original file line number Diff line number Diff line change 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)
You can’t perform that action at this time.
0 commit comments