[FFmpeg-cvslog] avcodec: move end zeroing code from av_packet_split_side_data() to avcodec_decode_subtitle2()

Michael Niedermayer git at videolan.org
Thu Jan 16 02:46:55 CET 2014


ffmpeg | branch: release/1.2 | Michael Niedermayer <michaelni at gmx.at> | Thu Nov 21 02:32:37 2013 +0100| [dea7f1c62e1af3e0967c7c85a8ab48ab6ffa1b47] | committer: Michael Niedermayer

avcodec: move end zeroing code from av_packet_split_side_data() to avcodec_decode_subtitle2()

This code changes the input packet, which is read only and can in
rare circumstances lead to decoder errors. (i run into one of these in
the audio decoder, which corrupted the packet during av_find_stream_info()
so that actual decoding that single packet failed later)
Until a better fix is implemented, this commit limits the problem.
A better fix might be to make the subtitle decoders not depend on
data[size] = 0 or to copy their input when this is not the case.
(cherry picked from commit 01923bab98506b1e98b4cbf08419364ce6ffea6d)

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=dea7f1c62e1af3e0967c7c85a8ab48ab6ffa1b47
---

 libavcodec/utils.c |   10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 969fe0c..bd3858b 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -1976,6 +1976,16 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
         int did_split = av_packet_split_side_data(&tmp);
         //apply_param_change(avctx, &tmp);
 
+        if (did_split) {
+            /* FFMIN() prevents overflow in case the packet wasn't allocated with
+             * proper padding.
+             * If the side data is smaller than the buffer padding size, the
+             * remaining bytes should have already been filled with zeros by the
+             * original packet allocation anyway. */
+            memset(tmp.data + tmp.size, 0,
+                   FFMIN(avpkt->size - tmp.size, FF_INPUT_BUFFER_PADDING_SIZE));
+        }
+
         pkt_recoded = tmp;
         ret = recode_subtitle(avctx, &pkt_recoded, &tmp);
         if (ret < 0) {



More information about the ffmpeg-cvslog mailing list