diff options
author | Pierre Joye <pierre.php@gmail.com> | 2016-07-19 14:16:20 +0700 |
---|---|---|
committer | Pierre Joye <pierre.php@gmail.com> | 2016-07-19 14:16:20 +0700 |
commit | 05e8a0febe12b267190c2bb40282e6b5eb642597 (patch) | |
tree | ebf2b6e670af780672400d1452891751485825ee | |
parent | 740661bd7a4aff947acf4b7c505650eb1fd5dceb (diff) | |
parent | b61bd1243ab5e2f17f7e9afecfdc47c6f1a05936 (diff) | |
download | php-git-05e8a0febe12b267190c2bb40282e6b5eb642597.tar.gz |
Merge branch 'PHP-5.6' into PHP-7.0
* PHP-5.6:
fix #72519, possible OOB using imagegif
-rw-r--r-- | ext/gd/libgd/gd_gif_out.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/ext/gd/libgd/gd_gif_out.c b/ext/gd/libgd/gd_gif_out.c index f094f46d41..1f2a6b936a 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); } } |