diff mbox series

[FFmpeg-devel] avcodec/mjpegdec: Try to continue decoding on zero quant matrix value

Message ID 20210703162528.177176-1-andriy.gelman@gmail.com
State Accepted
Commit 78f21f4ec161b9eacb75823740eabd3b87b44efe
Headers show
Series [FFmpeg-devel] avcodec/mjpegdec: Try to continue decoding on zero quant matrix value
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Andriy Gelman July 3, 2021, 4:25 p.m. UTC
From: Andriy Gelman <andriy.gelman@gmail.com>

A zero value in the quantization matrix is invalid but in practice will
just set the transform coefficient to zero after inverse quantization.
Try to continue decoding if the AV_EF_EXPLODE flag is not set.

Fixes ticket #9287.

Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
---

The last frame in the sample of the ticket does not decode because the
input file appears truncated.
Something like the following patch would still be needed to output the final
frame:
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20210627135307.14008-1-michael@niedermayer.cc/

 libavcodec/mjpegdec.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Michael Niedermayer July 4, 2021, 7:28 p.m. UTC | #1
On Sat, Jul 03, 2021 at 12:25:28PM -0400, Andriy Gelman wrote:
> From: Andriy Gelman <andriy.gelman@gmail.com>
> 
> A zero value in the quantization matrix is invalid but in practice will
> just set the transform coefficient to zero after inverse quantization.
> Try to continue decoding if the AV_EF_EXPLODE flag is not set.
> 
> Fixes ticket #9287.
> 
> Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
> ---
> 
> The last frame in the sample of the ticket does not decode because the
> input file appears truncated.
> Something like the following patch would still be needed to output the final
> frame:
> https://patchwork.ffmpeg.org/project/ffmpeg/patch/20210627135307.14008-1-michael@niedermayer.cc/
> 
>  libavcodec/mjpegdec.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)

LGTM

thx

[...]
Andriy Gelman July 5, 2021, 5:02 p.m. UTC | #2
On Sun, 04. Jul 21:28, Michael Niedermayer wrote:
> On Sat, Jul 03, 2021 at 12:25:28PM -0400, Andriy Gelman wrote:
> > From: Andriy Gelman <andriy.gelman@gmail.com>
> > 
> > A zero value in the quantization matrix is invalid but in practice will
> > just set the transform coefficient to zero after inverse quantization.
> > Try to continue decoding if the AV_EF_EXPLODE flag is not set.
> > 
> > Fixes ticket #9287.
> > 
> > Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
> > ---
> > 
> > The last frame in the sample of the ticket does not decode because the
> > input file appears truncated.
> > Something like the following patch would still be needed to output the final
> > frame:
> > https://patchwork.ffmpeg.org/project/ffmpeg/patch/20210627135307.14008-1-michael@niedermayer.cc/
> > 
> >  libavcodec/mjpegdec.c | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)

> 
> LGTM
> 

Thanks, will apply.
diff mbox series

Patch

diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index 02a987fd0c..8172dca513 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -217,8 +217,10 @@  int ff_mjpeg_decode_dqt(MJpegDecodeContext *s)
         for (i = 0; i < 64; i++) {
             s->quant_matrixes[index][i] = get_bits(&s->gb, pr ? 16 : 8);
             if (s->quant_matrixes[index][i] == 0) {
-                av_log(s->avctx, AV_LOG_ERROR, "dqt: 0 quant value\n");
-                return AVERROR_INVALIDDATA;
+                int log_level = s->avctx->err_recognition & AV_EF_EXPLODE ? AV_LOG_ERROR : AV_LOG_WARNING;
+                av_log(s->avctx, log_level, "dqt: 0 quant value\n");
+                if (s->avctx->err_recognition & AV_EF_EXPLODE)
+                    return AVERROR_INVALIDDATA;
             }
         }