aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/magicyuv.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-08-31 19:47:50 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-09-01 11:05:38 +0200
commite8716b7e4c600577f43bd8519dfb30b214830fde (patch)
tree8ff2f091445c389f1a9fc787014fc5fbd06cf069 /libavcodec/magicyuv.c
parent18dbbff525dd03ed4faefadbe08f5916b9e23666 (diff)
downloadffmpeg-e8716b7e4c600577f43bd8519dfb30b214830fde.tar.gz
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>
Diffstat (limited to 'libavcodec/magicyuv.c')
-rw-r--r--libavcodec/magicyuv.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c
index 5578374429..f2204f3401 100644
--- a/libavcodec/magicyuv.c
+++ b/libavcodec/magicyuv.c
@@ -459,11 +459,15 @@ static int build_huffman(AVCodecContext *avctx, GetBitContext *gbit, int max)
int x = get_bits(gbit, 7);
int l = get_bitsz(gbit, b * 8) + 1;
- for (k = 0; k < l; k++)
- if (j + k < max)
- s->len[i][j + k] = x;
+ k = j + l;
+ if (k > max) {
+ 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) {
j = 0;
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) {
break;
}
- } else if (j > max) {
- av_log(avctx, AV_LOG_ERROR, "Invalid Huffman codes\n");
- return AVERROR_INVALIDDATA;
}
}