]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/dvdsub: fix partial packet assembly
authorwm4 <nfxjfg@googlemail.com>
Mon, 21 Sep 2015 16:16:35 +0000 (18:16 +0200)
committerwm4 <nfxjfg@googlemail.com>
Tue, 22 Sep 2015 15:41:01 +0000 (17:41 +0200)
Assuming the first and second packets are partial, this would append the
reassembly buffer (ctx->buf) to itself with the second
append_to_cached_buf() call, because buf is set to ctx->buf.

I do not know a valid sample file which triggers this, and do not know
if packets can be split into more than 2 sub-packets, but it triggered
with a (differently) broken sample file in trac issue #4872.

libavcodec/dvdsubdec.c

index 81432e13a62eb77506df9bb9fa281a247d5de93c..57eafbf2704119705e44d12959177cc30b23436f 100644 (file)
@@ -535,6 +535,7 @@ static int dvdsub_decode(AVCodecContext *avctx,
     const uint8_t *buf = avpkt->data;
     int buf_size = avpkt->size;
     AVSubtitle *sub = data;
+    int appended = 0;
     int is_menu;
 
     if (ctx->buf_size) {
@@ -545,12 +546,13 @@ static int dvdsub_decode(AVCodecContext *avctx,
         }
         buf = ctx->buf;
         buf_size = ctx->buf_size;
+        appended = 1;
     }
 
     is_menu = decode_dvd_subtitles(ctx, sub, buf, buf_size);
     if (is_menu == AVERROR(EAGAIN)) {
         *data_size = 0;
-        return append_to_cached_buf(avctx, buf, buf_size);
+        return appended ? 0 : append_to_cached_buf(avctx, buf, buf_size);
     }
 
     if (is_menu < 0) {