Skip to content

Commit e77c8e4

Browse files
committed
Merge branch 'PHP-7.1' into PHP-7.2
* PHP-7.1: Update NEWS Fix bug #78069 - Out-of-bounds read in iconv.c:_php_iconv_mime_decode() due to integer overflow Fix #77973: Uninitialized read in gdImageCreateFromXbm
2 parents a0c9d08 + 16e037b commit e77c8e4

File tree

5 files changed

+49
-2
lines changed

5 files changed

+49
-2
lines changed

ext/gd/libgd/gd_xbm.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,11 @@ gdImagePtr gdImageCreateFromXbm(FILE * fd)
136136
}
137137
h[3] = ch;
138138
}
139-
sscanf(h, "%x", &b);
139+
if (sscanf(h, "%x", &b) != 1) {
140+
php_gd_error("invalid XBM");
141+
gdImageDestroy(im);
142+
return 0;
143+
}
140144
for (bit = 1; bit <= max_bit; bit = bit << 1) {
141145
gdImageSetPixel(im, x++, y, (b & bit) ? 1 : 0);
142146
if (x == im->sx) {

ext/gd/tests/bug77973.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
?>

ext/iconv/iconv.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1664,7 +1664,9 @@ static php_iconv_err_t _php_iconv_mime_decode(smart_str *pretval, const char *st
16641664
* we can do at this point. */
16651665
if (*(p1 + 1) == '=') {
16661666
++p1;
1667-
--str_left;
1667+
if (str_left > 1) {
1668+
--str_left;
1669+
}
16681670
}
16691671

16701672
err = _php_iconv_appendl(pretval, encoded_word, (size_t)((p1 + 1) - encoded_word), cd_pl);

ext/iconv/tests/bug78069.data

107 Bytes
Binary file not shown.

ext/iconv/tests/bug78069.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Bug #78069 (Out-of-bounds read in iconv.c:_php_iconv_mime_decode() due to integer overflow)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('iconv')) die('skip ext/iconv required');
6+
?>
7+
--FILE--
8+
<?php
9+
$hdr = iconv_mime_decode_headers(file_get_contents(__DIR__ . "/bug78069.data"),2);
10+
var_dump(count($hdr));
11+
?>
12+
DONE
13+
--EXPECT--
14+
int(1)
15+
DONE

0 commit comments

Comments
 (0)