From 0726006390004457278254357ecb9bd36cb801c6 Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Wed, 20 Mar 2024 09:15:21 +0100 Subject: [PATCH 10/16] avformat/matroskaenc: return error if aac extradata changes extradata changing would result in an invalid 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 db41d3d1c2..a1616d619f 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -2895,6 +2895,16 @@ static int mkv_check_new_extra_data(AVFormatContext *s, const AVPacket *pkt) case AV_CODEC_ID_AAC: if (side_data_size && mkv->track.bc) { int 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(EINVAL); + } else { + // Already written + break; + } + } ret = get_aac_sample_rates(s, mkv, side_data, side_data_size, &track->sample_rate, &output_sample_rate); if (ret < 0) -- 2.39.3 (Apple Git-146)