File tree 2 files changed +31
-0
lines changed
2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -743,6 +743,12 @@ PHP_FUNCTION(imageloadfont)
743
743
font -> w = FLIPWORD (font -> w );
744
744
font -> h = FLIPWORD (font -> h );
745
745
font -> nchars = FLIPWORD (font -> nchars );
746
+ if (overflow2 (font -> nchars , font -> h ) || overflow2 (font -> nchars * font -> h , font -> w )) {
747
+ php_error_docref (NULL , E_WARNING , "Error reading font, invalid font header" );
748
+ efree (font );
749
+ php_stream_close (stream );
750
+ RETURN_FALSE ;
751
+ }
746
752
body_size = font -> w * font -> h * font -> nchars ;
747
753
}
748
754
@@ -753,6 +759,7 @@ PHP_FUNCTION(imageloadfont)
753
759
RETURN_FALSE ;
754
760
}
755
761
762
+ ZEND_ASSERT (body_size > 0 );
756
763
font -> data = emalloc (body_size );
757
764
b = 0 ;
758
765
while (b < body_size && (n = php_stream_read (stream , & font -> data [b ], body_size - b )) > 0 ) {
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Bug #81739 (OOB read due to insufficient validation in imageloadfont())
3
+ --SKIPIF--
4
+ <?php
5
+ if (!extension_loaded ("gd " )) die ("skip gd extension not available " );
6
+ ?>
7
+ --FILE--
8
+ <?php
9
+ $ s = fopen (__DIR__ . "/font.font " , "w " );
10
+ // header without character data
11
+ fwrite ($ s , "\x01\x00\x00\x00\x20\x00\x00\x00\x08\x00\x00\x00\x08\x00\x00\x00" );
12
+ fclose ($ s );
13
+ var_dump (imageloadfont (__DIR__ . "/font.font " ));
14
+ ?>
15
+ --CLEAN--
16
+ <?php
17
+ @unlink (__DIR__ . "/font.font " );
18
+ ?>
19
+ --EXPECTF--
20
+ Warning: imageloadfont(): %croduct of memory allocation multiplication would exceed INT_MAX, failing operation gracefully
21
+ in %s on line %d
22
+
23
+ Warning: imageloadfont(): Error reading font, invalid font header in %s on line %d
24
+ bool(false)
You can’t perform that action at this time.
0 commit comments