Skip to content

Commit 8705254

Browse files
committed
Merge branch 'PHP-7.0.8' into PHP-7.0
* PHP-7.0.8: iFixed bug #72446 - Integer Overflow in gdImagePaletteToTrueColor() resulting in heap overflow update NEWS fix tests fix build Fix bug #72455: Heap Overflow due to integer overflows Fix bug #72434: ZipArchive class Use After Free Vulnerability in PHP's GC algorithm and unserialize Fixed ##72433: Use After Free Vulnerability in PHP's GC algorithm and unserialize Fix bug #72407: NULL Pointer Dereference at _gdScaleVert Fix bug #72402: _php_mb_regex_ereg_replace_exec - double free Fix bug #72298 pass2_no_dither out-of-bounds access Fixed #72339 Integer Overflow in _gd2GetHeader() resulting in heap overflow Fix bug #72262 - do not overflow int Fix bug #72400 and #72403 - prevent signed int overflows for string lengths Fix bug #72275: don't allow smart_str to overflow int Fix bug #72340: Double Free Courruption in wddx_deserialize Fix bug #72321 - use efree() for emalloc allocation 5.6.23RC1 fix NEWS set versions Conflicts: configure.in main/php_version.h
2 parents d002037 + 2a65544 commit 8705254

File tree

19 files changed

+194
-5
lines changed

19 files changed

+194
-5
lines changed

ext/gd/libgd/gd.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ gdImagePtr gdImageCreate (int sx, int sy)
131131
return NULL;
132132
}
133133

134+
if (overflow2(sizeof(unsigned char *), sx)) {
135+
return NULL;
136+
}
137+
134138
im = (gdImage *) gdCalloc(1, sizeof(gdImage));
135139

136140
/* Row-major ever since gd 1.3 */

ext/gd/libgd/gd_gd2.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,18 @@ static int _gd2GetHeader(gdIOCtxPtr in, int *sx, int *sy, int *cs, int *vers, in
138138
if (gd2_compressed(*fmt)) {
139139
nc = (*ncx) * (*ncy);
140140
GD2_DBG(php_gd_error("Reading %d chunk index entries", nc));
141+
if (overflow2(sizeof(t_chunk_info), nc)) {
142+
goto fail1;
143+
}
141144
sidx = sizeof(t_chunk_info) * nc;
142145
if (sidx <= 0) {
143146
goto fail1;
144147
}
145148
cidx = gdCalloc(sidx, 1);
149+
if (cidx == NULL) {
150+
goto fail1;
151+
}
152+
146153
for (i = 0; i < nc; i++) {
147154
if (gdGetInt(&cidx[i].offset, in) != 1) {
148155
gdFree(cidx);

ext/gd/libgd/gd_interpolation.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,9 @@ static inline void _gdScaleVert (const gdImagePtr pSrc, const unsigned int src_w
10471047
}
10481048

10491049
contrib = _gdContributionsCalc(dst_height, src_height, (double)(dst_height) / (double)(src_height), pSrc->interpolation);
1050+
if (contrib == NULL) {
1051+
return;
1052+
}
10501053
/* scale each column */
10511054
for (u = 0; u < dst_width - 1; u++) {
10521055
_gdScaleCol(pSrc, src_width, pDst, dst_width, dst_height, u, contrib);

ext/gd/libgd/gd_topal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1329,7 +1329,7 @@ pass2_no_dither (j_decompress_ptr cinfo,
13291329
/* If the pixel is transparent, we assign it the palette index that
13301330
* will later be added at the end of the palette as the transparent
13311331
* index. */
1332-
if ((oim->transparent >= 0) && (oim->transparent == *(inptr - 1)))
1332+
if ((oim->transparent >= 0) && (oim->transparent == *inptr))
13331333
{
13341334
*outptr++ = nim->colorsTotal;
13351335
inptr++;

ext/gd/tests/bug72298.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Bug #72298: pass2_no_dither out-of-bounds access
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('gd')) die("skip gd extension not available\n");
6+
?>
7+
--FILE--
8+
<?php
9+
$img = imagecreatetruecolor (1 , 1);
10+
imagecolortransparent($img, 0);
11+
imagetruecolortopalette($img, false, 4);
12+
?>
13+
DONE
14+
--EXPECT--
15+
DONE

ext/gd/tests/bug72339.gd

64 MB
Binary file not shown.

ext/gd/tests/bug72339.phpt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
Bug #72339 Integer Overflow in _gd2GetHeader() resulting in heap overflow
3+
--SKIPIF--
4+
<?php if (!function_exists("imagecreatefromgd2")) print "skip"; ?>
5+
--FILE--
6+
<?php imagecreatefromgd2(dirname(__FILE__) . DIRECTORY_SEPARATOR . "bug72339.gd"); ?>
7+
--EXPECTF--
8+
Warning: imagecreatefromgd2(): gd warning: product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully
9+
in %sbug72339.php on line %d
10+
11+
Warning: imagecreatefromgd2(): '%sbug72339.gd' is not a valid GD2 file in %sbug72339.php on line %d

ext/mbstring/php_mbregex.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,6 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
988988
smart_str_free(&eval_buf);
989989
zval_ptr_dtor(&retval);
990990
} else {
991-
efree(description);
992991
if (!EG(exception)) {
993992
php_error_docref(NULL, E_WARNING, "Unable to call custom replacement function");
994993
}

ext/mbstring/tests/bug72402.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Bug #72402: _php_mb_regex_ereg_replace_exec - double free
3+
--SKIPIF--
4+
<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
5+
--FILE--
6+
<?php
7+
function throwit() {
8+
throw new Exception('it');
9+
}
10+
$var10 = "throwit";
11+
try {
12+
$var14 = mb_ereg_replace_callback("", $var10, "");
13+
} catch(Exception $e) {}
14+
?>
15+
DONE
16+
--EXPECT--
17+
DONE

ext/mcrypt/mcrypt.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,10 @@ PHP_FUNCTION(mcrypt_generic)
637637
if (mcrypt_enc_is_block_mode(pm->td) == 1) { /* It's a block algorithm */
638638
block_size = mcrypt_enc_get_block_size(pm->td);
639639
data_size = ((((int)data_len - 1) / block_size) + 1) * block_size;
640+
if (data_size <= 0) {
641+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Integer overflow in data size");
642+
RETURN_FALSE;
643+
}
640644
data_str = zend_string_alloc(data_size, 0);
641645
memset(ZSTR_VAL(data_str), 0, data_size);
642646
memcpy(ZSTR_VAL(data_str), data, data_len);
@@ -683,7 +687,11 @@ PHP_FUNCTION(mdecrypt_generic)
683687
if (mcrypt_enc_is_block_mode(pm->td) == 1) { /* It's a block algorithm */
684688
block_size = mcrypt_enc_get_block_size(pm->td);
685689
data_size = ((((int)data_len - 1) / block_size) + 1) * block_size;
686-
data_s = emalloc(data_size + 1);
690+
if (data_size <= 0) {
691+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Integer overflow in data size");
692+
RETURN_FALSE;
693+
}
694+
data_s = emalloc((size_t)data_size + 1);
687695
memset(data_s, 0, data_size);
688696
memcpy(data_s, data, data_len);
689697
} else { /* It's not a block algorithm */

0 commit comments

Comments
 (0)