]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/mjpegdec: Fix leak in case of invalid external Huffman tables
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>
Sat, 3 Apr 2021 12:12:44 +0000 (14:12 +0200)
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>
Sat, 3 Apr 2021 15:48:40 +0000 (17:48 +0200)
When using external Huffman tables fails during init, the decoder
reverts back to using the default Huffman tables; and when doing so,
the current VLC tables leak because init_default_huffman_tables()
doesn't free them before overwriting them.

Sample:
samples.ffmpeg.org/archive/all/avi+mjpeg+pcm_s16le++mjpeg-interlace.avi

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
libavcodec/mjpegdec.c

index 5583d2aa353a6a29809616909cc0b843ecc44ab2..776797d35b71982da4a1bcda62624bf46ddbb763 100644 (file)
@@ -76,6 +76,7 @@ static int init_default_huffman_tables(MJpegDecodeContext *s)
     int i, ret;
 
     for (i = 0; i < FF_ARRAY_ELEMS(ht); i++) {
+        ff_free_vlc(&s->vlcs[ht[i].class][ht[i].index]);
         ret = ff_mjpeg_build_vlc(&s->vlcs[ht[i].class][ht[i].index],
                                  ht[i].bits, ht[i].values,
                                  ht[i].class == 1, s->avctx);