summaryrefslogtreecommitdiff
path: root/ext/gd
diff options
context:
space:
mode:
authorStanislav Malyshev <stas@php.net>2019-01-06 12:50:10 -0800
committerStanislav Malyshev <stas@php.net>2019-01-06 12:50:10 -0800
commit0f148839b5944df8f36624df53aa8d7199718f19 (patch)
tree83544948712a768192d7f809c7683ecf48a4efe9 /ext/gd
parent3d9624e126366fe924f1374206e29c88a75c9361 (diff)
parente617f03066ce81d26f56c06d6bd7787c7de08703 (diff)
downloadphp-git-0f148839b5944df8f36624df53aa8d7199718f19.tar.gz
Merge branch 'PHP-7.3'
* PHP-7.3: Fix #77367: Negative size parameter in mb_split Fix #77369 - memcpy with negative length via crafted DNS response Fix more issues with encodilng length Fix #77270: imagecolormatch Out Of Bounds Write on Heap Fix bug #77380 (Global out of bounds read in xmlrpc base64 code) Fix bug #77371 (heap buffer overflow in mb regex functions - compile_string_node) Fix bug #77370 - check that we do not read past buffer end when parsing multibytes Fix #77269: Potential unsigned underflow in gdImageScale Fix bug #77247 (heap buffer overflow in phar_detect_phar_fname_ext) Fix bug #77242 (heap out of bounds read in xmlrpc_decode()) Regenerate certs for openssl tests
Diffstat (limited to 'ext/gd')
-rw-r--r--ext/gd/libgd/gd_color_match.c4
-rw-r--r--ext/gd/libgd/gd_interpolation.c18
-rw-r--r--ext/gd/tests/bug77269.phpt21
-rw-r--r--ext/gd/tests/bug77270.phpt18
4 files changed, 50 insertions, 11 deletions
diff --git a/ext/gd/libgd/gd_color_match.c b/ext/gd/libgd/gd_color_match.c
index a4e56b1c40..e6f539bc75 100644
--- a/ext/gd/libgd/gd_color_match.c
+++ b/ext/gd/libgd/gd_color_match.c
@@ -33,8 +33,8 @@ int gdImageColorMatch (gdImagePtr im1, gdImagePtr im2)
return -4; /* At least 1 color must be allocated */
}
- buf = (unsigned long *)safe_emalloc(sizeof(unsigned long), 5 * im2->colorsTotal, 0);
- memset( buf, 0, sizeof(unsigned long) * 5 * im2->colorsTotal );
+ buf = (unsigned long *)safe_emalloc(sizeof(unsigned long), 5 * gdMaxColors, 0);
+ memset( buf, 0, sizeof(unsigned long) * 5 * gdMaxColors );
for (x=0; x<im1->sx; x++) {
for( y=0; y<im1->sy; y++ ) {
diff --git a/ext/gd/libgd/gd_interpolation.c b/ext/gd/libgd/gd_interpolation.c
index 75ac4137a7..afe0d7b4bb 100644
--- a/ext/gd/libgd/gd_interpolation.c
+++ b/ext/gd/libgd/gd_interpolation.c
@@ -890,8 +890,13 @@ static inline LineContribType * _gdContributionsAlloc(unsigned int line_length,
{
unsigned int u = 0;
LineContribType *res;
- int overflow_error = 0;
+ size_t weights_size;
+ if (overflow2(windows_size, sizeof(double))) {
+ return NULL;
+ } else {
+ weights_size = windows_size * sizeof(double);
+ }
res = (LineContribType *) gdMalloc(sizeof(LineContribType));
if (!res) {
return NULL;
@@ -908,15 +913,10 @@ static inline LineContribType * _gdContributionsAlloc(unsigned int line_length,
return NULL;
}
for (u = 0 ; u < line_length ; u++) {
- if (overflow2(windows_size, sizeof(double))) {
- overflow_error = 1;
- } else {
- res->ContribRow[u].Weights = (double *) gdMalloc(windows_size * sizeof(double));
- }
- if (overflow_error == 1 || res->ContribRow[u].Weights == NULL) {
+ res->ContribRow[u].Weights = (double *) gdMalloc(weights_size);
+ if (res->ContribRow[u].Weights == NULL) {
unsigned int i;
- u--;
- for (i=0;i<=u;i++) {
+ for (i=0;i<u;i++) {
gdFree(res->ContribRow[i].Weights);
}
gdFree(res->ContribRow);
diff --git a/ext/gd/tests/bug77269.phpt b/ext/gd/tests/bug77269.phpt
new file mode 100644
index 0000000000..c89f674b8a
--- /dev/null
+++ b/ext/gd/tests/bug77269.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Bug #77269 (Potential unsigned underflow in gdImageScale)
+--SKIPIF--
+<?php
+if (!extension_loaded('gd')) die('skip gd extension not available');
+if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
+?>
+--INI--
+memory_limit=2G
+--FILE--
+<?php
+$im = imagecreate(2**28, 1);
+if(is_resource($im)) {
+ imagescale($im, 1, 1, IMG_TRIANGLE);
+}
+?>
+===DONE===
+--EXPECTF--
+Warning: imagescale():%S product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully
+ in %s on line %d
+===DONE===
diff --git a/ext/gd/tests/bug77270.phpt b/ext/gd/tests/bug77270.phpt
new file mode 100644
index 0000000000..1c4555a64d
--- /dev/null
+++ b/ext/gd/tests/bug77270.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Bug #77270 (imagecolormatch Out Of Bounds Write on Heap)
+--SKIPIF--
+<?php
+if (!extension_loaded('gd')) die('skip gd extension not available');
+if (!GD_BUNDLED && version_compare(GD_VERSION, '2.2.5', '<=')) die('skip upstream bugfix has not been released');
+?>
+--FILE--
+<?php
+$img1 = imagecreatetruecolor(0xfff, 0xfff);
+$img2 = imagecreate(0xfff, 0xfff);
+imagecolorallocate($img2, 0, 0, 0);
+imagesetpixel($img2, 0, 0, 255);
+imagecolormatch($img1, $img2);
+?>
+===DONE===
+--EXPECT--
+===DONE===