Skip to content

Commit

Permalink
Merge branch 'PHP-7.0'
Browse files Browse the repository at this point in the history
* PHP-7.0:
  fix #72519, possible OOB using imagegif
  • Loading branch information
pierrejoye committed Jul 19, 2016
2 parents 6434fc9 + 05e8a0f commit 2707271
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions ext/gd/libgd/gd_gif_out.c
Original file line number Diff line number Diff line change
Expand Up @@ -601,14 +601,26 @@ compress(int init_bits, gdIOCtxPtr outfile, gdImagePtr im, GifCtx *ctx)
* 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 )
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 2707271

Please sign in to comment.