diff options
author | Loren Merritt <lorenm@u.washington.edu> | 2009-07-04 23:59:10 +0000 |
---|---|---|
committer | Loren Merritt <lorenm@u.washington.edu> | 2009-07-04 23:59:10 +0000 |
commit | e30004fa733ec64b6ff90678098c1f1132d4d603 (patch) | |
tree | 740a34cf3df653ddab28cfe994262b973c4d28b4 /libavcodec/huffyuv.c | |
parent | 2483298ae2248cbac39940f2ae85c2b6ddec9282 (diff) | |
download | ffmpeg-e30004fa733ec64b6ff90678098c1f1132d4d603.tar.gz |
fix a buffer overrun on corrupt huffyuv streams
Originally committed as revision 19346 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/huffyuv.c')
-rw-r--r-- | libavcodec/huffyuv.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/libavcodec/huffyuv.c b/libavcodec/huffyuv.c index ad2f25ffe3..40d980da45 100644 --- a/libavcodec/huffyuv.c +++ b/libavcodec/huffyuv.c @@ -213,7 +213,7 @@ static inline void sub_left_prediction_bgr32(HYuvContext *s, uint8_t *dst, uint8 *blue= src[(w-1)*4+B]; } -static void read_len_table(uint8_t *dst, GetBitContext *gb){ +static int read_len_table(uint8_t *dst, GetBitContext *gb){ int i, val, repeat; for(i=0; i<256;){ @@ -222,9 +222,14 @@ static void read_len_table(uint8_t *dst, GetBitContext *gb){ if(repeat==0) repeat= get_bits(gb, 8); //printf("%d %d\n", val, repeat); + if(i+repeat > 256) { + av_log(NULL, AV_LOG_ERROR, "Error reading huffman table\n"); + return -1; + } while (repeat--) dst[i++] = val; } + return 0; } static int generate_bits_table(uint32_t *dst, uint8_t *len_table){ @@ -379,8 +384,8 @@ static int read_huffman_tables(HYuvContext *s, uint8_t *src, int length){ init_get_bits(&gb, src, length*8); for(i=0; i<3; i++){ - read_len_table(s->len[i], &gb); - + if(read_len_table(s->len[i], &gb)<0) + return -1; if(generate_bits_table(s->bits[i], s->len[i])<0){ return -1; } @@ -404,9 +409,11 @@ static int read_old_huffman_tables(HYuvContext *s){ int i; init_get_bits(&gb, classic_shift_luma, sizeof(classic_shift_luma)*8); - read_len_table(s->len[0], &gb); + if(read_len_table(s->len[0], &gb)<0) + return -1; init_get_bits(&gb, classic_shift_chroma, sizeof(classic_shift_chroma)*8); - read_len_table(s->len[1], &gb); + if(read_len_table(s->len[1], &gb)<0) + return -1; for(i=0; i<256; i++) s->bits[0][i] = classic_add_luma [i]; for(i=0; i<256; i++) s->bits[1][i] = classic_add_chroma[i]; |