[FFmpeg-devel] [PATCH] avformat/matroskaenc: return error if aac extradata changes

John Stebbins jstebbins at jetheaddev.com
Sat May 2 18:39:45 EEST 2020


extradata changing would result in an invalid and undecodable stream.
Also, as the code was written, rewriting extradata was corrupting the
track header resulting in an invalid file.
---
 libavformat/matroskaenc.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 784973a951..ae5636f71d 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -2183,6 +2183,16 @@ static int mkv_check_new_extra_data(AVFormatContext *s, const AVPacket *pkt)
     case AV_CODEC_ID_AAC:
         if (side_data_size && (s->pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live) {
             int filler, output_sample_rate = 0;
+            if (par->extradata && par->extradata_size) {
+                if (par->extradata_size != side_data_size ||
+                    memcmp(par->extradata, side_data, side_data_size)) {
+                    av_log(s, AV_LOG_ERROR, "Error, AAC extradata changed mid-stream.\n");
+                    return AVERROR_INPUT_CHANGED;
+                } else { // Already written
+                    break;
+                }
+            }
+
             ret = get_aac_sample_rates(s, side_data, side_data_size, &track->sample_rate,
                                        &output_sample_rate);
             if (ret < 0)
-- 
2.25.4



More information about the ffmpeg-devel mailing list