com php-src: Fixed bug #75571: Potential infinite loop in gdImageCreateFromGifCtx: ext/gd/libgd/gd_gif_in.c ext/g d/tests/bug75571.gif
ext/gd/tests/bug7557 1.phpt
| From: | Stanislav Malyshev | Date: | Tue, 02 Jan 2018 03:51:26 +0000 |
| Subject: | com php-src: Fixed bug #75571: Potential infinite loop in gdImageCreateFromGifCtx: ext/gd/libgd/gd_gif_in.c ext/g d/tests/bug75571.gif ext/gd/tests/bug7557 1.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-100727@lists.php.net to get a copy of this message | ||
Commit: 8d6e9588671136837533fe3785657c31c5b52767
Author: Christoph M. Becker <cmbecker69@gmx.de> Wed, 29 Nov 2017 18:52:33 +0100
Committer: Stanislav Malyshev <stas@php.net> Mon, 1 Jan 2018 19:51:26 -0800
Parents: 73ca9b37731dd9690ffd9706333b17eaf90ea091
Branches: PHP-5..6
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=8d6e9588671136837533fe3785657c31c5b52767
Log:
Fixed bug #75571: Potential infinite loop in gdImageCreateFromGifCtx
Due to a signedness confusion in
GetCode_ a corrupt GIF file can
trigger an infinite loop. Furthermore we make sure that a GIF without
any palette entries is treated as invalid *after* open palette entries
have been removed.
Bugs:
https://bugs.php.net/75571
Changed paths:
M ext/gd/libgd/gd_gif_in..c
A ext/gd/tests/bug75571.gif
A ext/gd/tests/bug75571.phpt
Diff:
diff --git a/ext/gd/libgd/gd_gif_in.c b/ext/gd/libgd/gd_gif_in.c
index e0f0fe3..16776d3 100644
--- a/ext/gd/libgd/gd_gif_in.c
+++ b/ext/gd/libgd/gd_gif_in.c
@@ -261,10 +261,6 @@ terminated:
if (!im) {
return 0;
}
- if (!im->colorsTotal) {
- gdImageDestroy(im);
- return 0;
- }
/* Check for open colors at the end, so
we can reduce colorsTotal and ultimately
BitsPerPixel */
@@ -275,6 +271,10 @@ terminated:
break;
}
}
+ if (!im->colorsTotal) {
+ gdImageDestroy(im);
+ return 0;
+ }
return im;
}
/* }}} */
@@ -375,7 +375,7 @@ static int
GetCode_(gdIOCtx *fd, CODE_STATIC_DATA *scd, int code_size, int flag, int *ZeroDataBlockP)
{
int i, j, ret;
- unsigned char count;
+ int count;
if (flag) {
scd->curbit = 0;
diff --git a/ext/gd/tests/bug75571.gif b/ext/gd/tests/bug75571.gif
new file mode 100644
index 0000000..3c30b40
Binary files /dev/null and b/ext/gd/tests/bug75571.gif differ
diff --git a/ext/gd/tests/bug75571.phpt b/ext/gd/tests/bug75571.phpt
new file mode 100644
index 0000000..5bd26b8
--- /dev/null
+++ b/ext/gd/tests/bug75571.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Bug #75571 (Infinite loop in GIF reading causing DoS)
+--SKIPIF--
+<?php
+if (!extension_loaded('gd')) die('skip gd extension not available');
+?>
+--FILE--
+<?php
+var_dump(imagecreatefromgif(__DIR__ . '/bug75571.gif'));
+?>
+===DONE===
+--EXPECTF--
+Warning: imagecreatefromgif(): '%s' is not a valid GIF file in %s on line %d
+bool(false)
+===DONE===