PR #24447 opened by James Almer (jamrial)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24447
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24447.patch

Too many merge conflicts to attempt individual cherry-picks.


>From 1a769dec777e07e4c41f21c810477f1f859100e9 Mon Sep 17 00:00:00 2001
From: James Almer <[email protected]>
Date: Thu, 10 Sep 2026 16:46:30 -0300
Subject: [PATCH] avformat/iamf: backport assorted fixes

Too many merge conflics to attempt individual cherry-picks.

Signed-off-by: James Almer <[email protected]>
---
 libavformat/iamf_parse.c  |  5 +++++
 libavformat/iamf_writer.c | 17 ++++++++++++-----
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/libavformat/iamf_parse.c b/libavformat/iamf_parse.c
index 12d348a705..892145cd87 100644
--- a/libavformat/iamf_parse.c
+++ b/libavformat/iamf_parse.c
@@ -1011,6 +1011,11 @@ static int mix_presentation_obu(void *s, IAMFContext *c, 
AVIOContext *pb, int le
     mix_presentation->cmix = mix;
 
     mix_presentation->count_label = ffio_read_leb(pbc);
+    if (mix_presentation->count_label > len - avio_tell(pbc)) {
+        mix_presentation->count_label = 0;
+        ret = AVERROR_INVALIDDATA;
+        goto fail;
+    }
     mix_presentation->language_label = av_calloc(mix_presentation->count_label,
                                                  
sizeof(*mix_presentation->language_label));
     if (!mix_presentation->language_label) {
diff --git a/libavformat/iamf_writer.c b/libavformat/iamf_writer.c
index ef7cecab27..0c43b64f83 100644
--- a/libavformat/iamf_writer.c
+++ b/libavformat/iamf_writer.c
@@ -100,12 +100,18 @@ static int populate_audio_roll_distance(IAMFCodecConfig 
*codec_config)
 }
 
 static int fill_codec_config(IAMFContext *iamf, const AVStreamGroup *stg,
-                             IAMFCodecConfig *codec_config)
+                             IAMFCodecConfig *codec_config, void *log_ctx)
 {
     const AVStream *st = stg->streams[0];
     IAMFCodecConfig **tmp;
     int j, ret = 0;
 
+    if (!st->codecpar->frame_size) {
+        av_log(log_ctx, AV_LOG_ERROR, "frame_size is unset for stream id %d\n",
+               st->id);
+        return AVERROR(EINVAL);
+    }
+
     codec_config->codec_id = st->codecpar->codec_id;
     codec_config->codec_tag = st->codecpar->codec_tag;
     switch (codec_config->codec_id) {
@@ -308,7 +314,7 @@ int ff_iamf_add_audio_element(IAMFContext *iamf, const 
AVStreamGroup *stg, void
     if (!codec_config)
         return AVERROR(ENOMEM);
 
-    ret = fill_codec_config(iamf, stg, codec_config);
+    ret = fill_codec_config(iamf, stg, codec_config, log_ctx);
     if (ret < 0) {
         av_free(codec_config);
         return ret;
@@ -1239,9 +1245,10 @@ int ff_iamf_write_audio_frame(const IAMFContext *iamf, 
AVIOContext *pb,
 
     if (codec_config->codec_id == AV_CODEC_ID_OPUS) {
         // IAMF's num_samples_to_trim_at_start is the same as Opus's pre-skip.
-        skip_samples = pkt->dts < 0
-            ? av_rescale(-pkt->dts, 48000, pkt->time_base.den)
-            : 0;
+        if (!skip_samples)
+            skip_samples = pkt->dts < 0
+                ? av_rescale(-pkt->dts, 48000, pkt->time_base.den)
+                : 0;
         discard_padding = av_rescale(discard_padding, 48000, 
pkt->time_base.den);
     }
 
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to