avcodec/magicyuv: Simplify check for invalid Huffman codes

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
This commit is contained in:
Andreas Rheinhardt 2020-08-31 19:47:50 +02:00
parent 18dbbff525
commit e8716b7e4c
1 changed files with 8 additions and 7 deletions

View File

@ -459,11 +459,15 @@ static int build_huffman(AVCodecContext *avctx, GetBitContext *gbit, int max)
int x = get_bits(gbit, 7); int x = get_bits(gbit, 7);
int l = get_bitsz(gbit, b * 8) + 1; int l = get_bitsz(gbit, b * 8) + 1;
for (k = 0; k < l; k++) k = j + l;
if (j + k < max) if (k > max) {
s->len[i][j + k] = x; av_log(avctx, AV_LOG_ERROR, "Invalid Huffman codes\n");
return AVERROR_INVALIDDATA;
}
for (; j < k; j++)
s->len[i][j] = x;
j += l;
if (j == max) { if (j == max) {
j = 0; j = 0;
if (s->huff_build(&s->vlc[i], s->len[i])) { if (s->huff_build(&s->vlc[i], s->len[i])) {
@ -474,9 +478,6 @@ static int build_huffman(AVCodecContext *avctx, GetBitContext *gbit, int max)
if (i == s->planes) { if (i == s->planes) {
break; break;
} }
} else if (j > max) {
av_log(avctx, AV_LOG_ERROR, "Invalid Huffman codes\n");
return AVERROR_INVALIDDATA;
} }
} }