diff mbox series

[FFmpeg-devel,1/3] avcodec/sheervideo: Don't leave context in inconsistent state upon error

Message ID 20201010185956.980042-1-andreas.rheinhardt@gmail.com
State Accepted
Commit 8969b9aa061790a5e87694aab17741cc7647d099
Headers show
Series [FFmpeg-devel,1/3] avcodec/sheervideo: Don't leave context in inconsistent state upon error | expand

Checks

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

Commit Message

Andreas Rheinhardt Oct. 10, 2020, 6:59 p.m. UTC
This has happened if the format changed midstream and if the new packet
is so small that it is instantaneously rejected: In this case the VLC
tables were for the new format, although the context says that they are
still the ones for the old format. It can also happen if the format
changed midstream and the allocation of the new tables fails. If the
next packet is a packet for the old format, the decoder thinks it
already has the correct VLC tables, leading to a segfault.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/sheervideo.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/sheervideo.c b/libavcodec/sheervideo.c
index e1a203d361..099e5fdf22 100644
--- a/libavcodec/sheervideo.c
+++ b/libavcodec/sheervideo.c
@@ -2034,16 +2034,17 @@  static int decode_frame(AVCodecContext *avctx,
         return AVERROR_PATCHWELCOME;
     }
 
-    if (avpkt->size < 20 + avctx->width * avctx->height / 16) {
-        av_log(avctx, AV_LOG_ERROR, "Input packet too small\n");
-        return AVERROR_INVALIDDATA;
-    }
-
     if (s->format != format) {
-        if (ret < 0)
+        if (ret < 0) {
+            s->format = 0;
             return ret;
+        }
         s->format = format;
     }
+    if (avpkt->size < 20 + avctx->width * avctx->height / 16) {
+        av_log(avctx, AV_LOG_ERROR, "Input packet too small\n");
+        return AVERROR_INVALIDDATA;
+    }
 
     p->pict_type = AV_PICTURE_TYPE_I;
     p->key_frame = 1;