com php-src: fix #72519, possible OOB using imagegif: ext/gd/libgd/gd_gif_out.c
| From: | Ferenc Kovacs | Date: | Thu, 21 Jul 2016 00:14:40 +0000 |
| Subject: | com php-src: fix #72519, possible OOB using imagegif: ext/gd/libgd/gd_gif_out.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-93280@lists.php.net to get a copy of this message | ||
Commit: a48f64c403b05da244cfd30399bffd53e910a440
Author: Pierre Joye <pierre.php@gmail.com> Tue, 19 Jul 2016 14:11:44 +0700
Committer: Ferenc Kovacs <tyra3l@gmail.com> Thu, 21 Jul 2016 02:14:40 +0200
Parents: 210222928e52b95827a0b5e4a987303233597f89
Branches: PHP-5.6.24
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=a48f64c403b05da244cfd30399bffd53e910a440
Log:
fix #72519, possible OOB using imagegif
Bugs:
https://bugs.php.net/72519
Changed paths:
M ext/gd/libgd/gd_gif_out.c
Diff:
diff --git a/ext/gd/libgd/gd_gif_out.c b/ext/gd/libgd/gd_gif_out.c
index 1404538..0178dd9 100644
--- a/ext/gd/libgd/gd_gif_out.c
+++ b/ext/gd/libgd/gd_gif_out.c
@@ -601,14 +601,26 @@ nomatch:
* code in turn. When the buffer fills up empty it and start over.
*/
-static unsigned long masks[] = { 0x0000, 0x0001, 0x0003, 0x0007, 0x000F,
+static const unsigned long masks[] = { 0x0000, 0x0001, 0x0003, 0x0007, 0x000F,
0x001F, 0x003F, 0x007F, 0x00FF,
0x01FF, 0x03FF, 0x07FF, 0x0FFF,
0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF };
+
+/* Arbitrary value to mark output is done. When we see EOFCode, then we don't
+ * expect to see any more data. If we do (e.g. corrupt image inputs), cur_bits
+ * might be negative, so flag it to return early.
+ */
+#define CUR_BITS_FINISHED -1000
+
+
static void
output(code_int code, GifCtx *ctx)
{
+ if (ctx->cur_bits == CUR_BITS_FINISHED) {
+ return;
+ }
+
ctx->cur_accum &= masks[ ctx->cur_bits ];
if( ctx->cur_bits > 0 )
@@ -655,8 +667,10 @@ output(code_int code, GifCtx *ctx)
ctx->cur_bits -= 8;
}
- flush_char(ctx);
+ /* Flag that it's done to prevent re-entry. */
+ ctx->cur_bits = CUR_BITS_FINISHED;
+ flush_char(ctx);
}
}