File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -135,7 +135,11 @@ gdImagePtr gdImageCreateFromXbm(FILE * fd)
135
135
}
136
136
h [3 ] = ch ;
137
137
}
138
- sscanf (h , "%x" , & b );
138
+ if (sscanf (h , "%x" , & b ) != 1 ) {
139
+ php_gd_error ("invalid XBM" );
140
+ gdImageDestroy (im );
141
+ return 0 ;
142
+ }
139
143
for (bit = 1 ; bit <= max_bit ; bit = bit << 1 ) {
140
144
gdImageSetPixel (im , x ++ , y , (b & bit ) ? 1 : 0 );
141
145
if (x == im -> sx ) {
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Bug #77973 (Uninitialized read in gdImageCreateFromXbm)
3
+ --SKIPIF--
4
+ <?php
5
+ if (!extension_loaded ('gd ' )) die ("skip gd extension not available " );
6
+ if (!function_exists ('imagecreatefromxbm ' )) die ("skip imagecreatefromxbm not available " );
7
+ ?>
8
+ --FILE--
9
+ <?php
10
+ $ contents = hex2bin ("23646566696e6520776964746820320a23646566696e652068656967687420320a737461746963206368617220626974735b5d203d7b0a7a7a787a7a " );
11
+ $ filepath = __DIR__ . '/bug77973.xbm ' ;
12
+ file_put_contents ($ filepath , $ contents );
13
+ $ im = imagecreatefromxbm ($ filepath );
14
+ var_dump ($ im );
15
+ ?>
16
+ ===DONE===
17
+ --EXPECTF--
18
+ Warning: imagecreatefromxbm(): invalid XBM in %s on line %d
19
+
20
+ Warning: imagecreatefromxbm(): '%s' is not a valid XBM file in %s on line %d
21
+ bool(false)
22
+ ===DONE===
23
+ --CLEAN--
24
+ <?php
25
+ unlink (__DIR__ . '/bug77973.xbm ' );
26
+ ?>
You can’t perform that action at this time.
0 commit comments