Commit 0269ae4b authored by bcoudurier's avatar bcoudurier

add some length checks

git-svn-id: file:///var/local/repositories/ffmpeg/trunk@8501 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent 16d44dee
...@@ -48,6 +48,7 @@ typedef struct GifState { ...@@ -48,6 +48,7 @@ typedef struct GifState {
/* LZW compatible decoder */ /* LZW compatible decoder */
uint8_t *bytestream; uint8_t *bytestream;
uint8_t *bytestream_end;
LZWState *lzw; LZWState *lzw;
/* aux buffers */ /* aux buffers */
...@@ -209,6 +210,9 @@ static int gif_read_header1(GifState *s) ...@@ -209,6 +210,9 @@ static int gif_read_header1(GifState *s)
int v, n; int v, n;
int has_global_palette; int has_global_palette;
if (s->bytestream_end < s->bytestream + 13)
return -1;
/* read gif signature */ /* read gif signature */
bytestream_get_buffer(&s->bytestream, sig, 6); bytestream_get_buffer(&s->bytestream, sig, 6);
if (memcmp(sig, gif87a_sig, 6) != 0 && if (memcmp(sig, gif87a_sig, 6) != 0 &&
...@@ -238,6 +242,8 @@ static int gif_read_header1(GifState *s) ...@@ -238,6 +242,8 @@ static int gif_read_header1(GifState *s)
#endif #endif
if (has_global_palette) { if (has_global_palette) {
n = 1 << s->bits_per_pixel; n = 1 << s->bits_per_pixel;
if (s->bytestream_end < s->bytestream + n * 3)
return -1;
bytestream_get_buffer(&s->bytestream, s->global_palette, n * 3); bytestream_get_buffer(&s->bytestream, s->global_palette, n * 3);
} }
return 0; return 0;
...@@ -245,7 +251,7 @@ static int gif_read_header1(GifState *s) ...@@ -245,7 +251,7 @@ static int gif_read_header1(GifState *s)
static int gif_parse_next_image(GifState *s) static int gif_parse_next_image(GifState *s)
{ {
for (;;) { while (s->bytestream < s->bytestream_end) {
int code = bytestream_get_byte(&s->bytestream); int code = bytestream_get_byte(&s->bytestream);
#ifdef DEBUG #ifdef DEBUG
dprintf(s->avctx, "gif: code=%02x '%c'\n", code, code); dprintf(s->avctx, "gif: code=%02x '%c'\n", code, code);
...@@ -289,6 +295,7 @@ static int gif_decode_frame(AVCodecContext *avctx, void *data, int *data_size, u ...@@ -289,6 +295,7 @@ static int gif_decode_frame(AVCodecContext *avctx, void *data, int *data_size, u
int ret; int ret;
s->bytestream = buf; s->bytestream = buf;
s->bytestream_end = buf + buf_size;
if (gif_read_header1(s) < 0) if (gif_read_header1(s) < 0)
return -1; return -1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment