com php-src: Fix #72494: imagecropauto out-of-bounds access: NEWS ext/gd/libgd/gd_crop.c ext/gd/tests/bug72494. phpt
| From: | Christoph Michael Becker | Date: | Tue, 25 Oct 2016 12:29:48 +0000 |
| Subject: | com php-src: Fix #72494: imagecropauto out-of-bounds access: NEWS ext/gd/libgd/gd_crop.c ext/gd/tests/bug72494. phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-95279@lists.php.net to get a copy of this message | ||
Commit: cd13d0260a9327af541176235e76cdef8af3a27a
Author: Christoph M. Becker <cmbecker69@gmx.de> Tue, 25 Oct 2016 14:19:36 +0200
Parents: 4f5a755b9d08abafe06152b815294c2fff03927a
Branches: PHP-5.6 PHP-7..0 PHP-7.1 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=cd13d0260a9327af541176235e76cdef8af3a27a
Log:
Fix #72494: imagecropauto out-of-bounds access
This issue has actually already been fixed with commit 46f2c690. We're
adding a regression test and a NEWS entry, and also port the fix in
gdImageCropThreshold() from libgd:
* <https://github.com/libgd/libgd/commit/b347e034>
* <https://github.com/libgd/libgd/commit/46f2c690>
Bugs:
https://bugs.php.net/72494
Changed paths:
M NEWS
M ext/gd/libgd/gd_crop.c
A ext/gd/tests/bug72494.phpt
Diff:
diff --git a/NEWS b/NEWS
index fc2e52c...d3cac72 100644
--- a/NEWS
+++ b/NEWS
@@ -273,6 +273,8 @@ PHP NEWS
.. Fixed bug #72697 (select_colors write out-of-bounds). (Stas)
. Fixed bug #72709 (imagesetstyle() causes OOB read for empty $styles). (cmb)
. Fixed bug #72730 (imagegammacorrect allows arbitrary write access). (Stas)
+ . Fixed bug #72494 (imagecropauto out-of-bounds access). (Fernando, Pierre,
+ cmb)
- Intl:
. Partially fixed #72506 (idn_to_ascii for UTS #46 incorrect for long domain
diff --git a/ext/gd/libgd/gd_crop.c b/ext/gd/libgd/gd_crop.c
index 8331521..58b6303 100644
--- a/ext/gd/libgd/gd_crop.c
+++ b/ext/gd/libgd/gd_crop.c
@@ -243,6 +243,10 @@ gdImagePtr gdImageCropThreshold(gdImagePtr im, const unsigned int color, const
f
return NULL;
}
+ if (!gdImageTrueColor(im) && color >= gdImageColorsTotal(im)) {
+ return NULL;
+ }
+
/* TODO: Add gdImageGetRowPtr and works with ptr at the row level
* for the true color and palette images
* new formats will simply work with ptr
diff --git a/ext/gd/tests/bug72494.phpt b/ext/gd/tests/bug72494..phpt
new file mode 100644
index 0000000..f21de6c
--- /dev/null
+++ b/ext/gd/tests/bug72494.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Bug #72494 (imagecropauto out-of-bounds access)
+--SKIPIF--
+<?php
+if (!extension_loaded('gd')) die('skip gd extension not available');
+?>
+--FILE--
+<?php
+$im = imagecreate(10,10);
+imagecropauto($im, IMG_CROP_THRESHOLD, 0, 1337);
+?>
+===DONE===
+--EXPECTF--
+Warning: imagecropauto(): Color argument missing with threshold mode in %s on line %d
+===DONE===