Commit be373cb5 authored by Luca Barbato's avatar Luca Barbato

4xm: do not overread the prestream buffer

Reported-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
CC: libav-stable@libav.org
parent de2e5777
...@@ -579,7 +579,8 @@ static int decode_i_mb(FourXContext *f) ...@@ -579,7 +579,8 @@ static int decode_i_mb(FourXContext *f)
} }
static const uint8_t *read_huffman_tables(FourXContext *f, static const uint8_t *read_huffman_tables(FourXContext *f,
const uint8_t * const buf) const uint8_t * const buf,
int len)
{ {
int frequency[512] = { 0 }; int frequency[512] = { 0 };
uint8_t flag[512]; uint8_t flag[512];
...@@ -597,12 +598,20 @@ static const uint8_t *read_huffman_tables(FourXContext *f, ...@@ -597,12 +598,20 @@ static const uint8_t *read_huffman_tables(FourXContext *f,
for (;;) { for (;;) {
int i; int i;
len -= end - start + 1;
if (end < start || len < 0)
return NULL;
for (i = start; i <= end; i++) for (i = start; i <= end; i++)
frequency[i] = *ptr++; frequency[i] = *ptr++;
start = *ptr++; start = *ptr++;
if (start == 0) if (start == 0)
break; break;
if (--len < 0)
return NULL;
end = *ptr++; end = *ptr++;
} }
frequency[256] = 1; frequency[256] = 1;
...@@ -744,7 +753,7 @@ static int decode_i_frame(FourXContext *f, AVFrame *frame, const uint8_t *buf, i ...@@ -744,7 +753,7 @@ static int decode_i_frame(FourXContext *f, AVFrame *frame, const uint8_t *buf, i
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
prestream = read_huffman_tables(f, prestream); prestream = read_huffman_tables(f, prestream, prestream_size);
if (!prestream) { if (!prestream) {
av_log(f->avctx, AV_LOG_ERROR, "Error reading Huffman tables.\n"); av_log(f->avctx, AV_LOG_ERROR, "Error reading Huffman tables.\n");
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
......
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