This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch master
in repository ffmpeg.

The following commit(s) were added to refs/heads/master by this push:
     new 019b1b45ce avformat/cafdec: clamp the Opus pre-skip to 16 bits
019b1b45ce is described below

commit 019b1b45cec4ba641d8897b8956ddfa61e098c28
Author:     Baptiste Coudurier <[email protected]>
AuthorDate: Sat Nov 21 12:09:25 2026 -0800
Commit:     Baptiste Coudurier <[email protected]>
CommitDate: Sat Nov 21 23:49:33 2026 +0000

    avformat/cafdec: clamp the Opus pre-skip to 16 bits
    
    Priming beyond 65535 frames wrapped in the OpusHead; warn and clamp
    instead, keeping the full priming in initial_padding.
    
    Signed-off-by: Baptiste Coudurier <[email protected]>
---
 libavformat/cafdec.c                  | 16 ++++++++++++++--
 tests/fate/caf.mak                    |  7 ++++++-
 tests/ref/fate/caf-opus-large-priming |  7 +++++++
 3 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/libavformat/cafdec.c b/libavformat/cafdec.c
index fae4d7db5e..c296946bba 100644
--- a/libavformat/cafdec.c
+++ b/libavformat/cafdec.c
@@ -114,6 +114,18 @@ static int read_desc_chunk(AVFormatContext *s)
     return 0;
 }
 
+/**
+ * Store the priming in the OpusHead pre-skip, which is limited to 16 bits.
+ * initial_padding keeps the full priming.
+ */
+static void set_opus_pre_skip(AVFormatContext *s, AVCodecParameters *par)
+{
+    if (par->initial_padding > UINT16_MAX)
+        av_log(s, AV_LOG_WARNING, "priming of %d frames does not fit "
+               "in the Opus pre-skip, clamping\n", par->initial_padding);
+    AV_WL16A(par->extradata + 10, FFMIN(par->initial_padding, UINT16_MAX));
+}
+
 /** Read magic cookie chunk */
 static int read_kuki_chunk(AVFormatContext *s, int64_t size)
 {
@@ -244,7 +256,7 @@ static int read_kuki_chunk(AVFormatContext *s, int64_t size)
         AV_WB32A(st->codecpar->extradata + 4, MKBETAG('H','e','a','d'));
         AV_WB8(st->codecpar->extradata + 8, 1); /* OpusHead version */
         AV_WB8(st->codecpar->extradata + 9, 
st->codecpar->ch_layout.nb_channels);
-        AV_WL16A(st->codecpar->extradata + 10, st->codecpar->initial_padding);
+        set_opus_pre_skip(s, st->codecpar);
         AV_WL32A(st->codecpar->extradata + 12, st->codecpar->sample_rate);
         AV_WL16A(st->codecpar->extradata + 16, 0);
         AV_WB8(st->codecpar->extradata + 18, 0);
@@ -286,7 +298,7 @@ static int read_pakt_chunk(AVFormatContext *s, int64_t size)
     st->nb_frames += caf->remainder;
 
     if (st->codecpar->codec_id == AV_CODEC_ID_OPUS && 
st->codecpar->extradata_size)
-        AV_WL16A(st->codecpar->extradata + 10, st->codecpar->initial_padding);
+        set_opus_pre_skip(s, st->codecpar);
 
     if (caf->bytes_per_packet > 0 && caf->frames_per_packet > 0) {
         if (!num_packets) {
diff --git a/tests/fate/caf.mak b/tests/fate/caf.mak
index 4ee9c95a5c..a15895efdb 100644
--- a/tests/fate/caf.mak
+++ b/tests/fate/caf.mak
@@ -21,6 +21,11 @@ fate-caf-pcm_s24-remux: CMD = transcode wav 
$(TARGET_SAMPLES)/audio-reference/di
 FATE_CAF_FFMPEG-$(call REMUX, CAF, MOV_DEMUXER) += fate-caf-mace6-remux
 fate-caf-mace6-remux: CMD = transcode mov 
$(TARGET_SAMPLES)/qtrle/Animation-16Greys.mov caf "-map 0:a -c copy" "-c copy 
-t 0.003"
 
+# priming beyond the 16-bit OpusHead pre-skip
+FATE_CAF_FFPROBE-$(call DEMDEC, CAF, OPUS) += fate-caf-opus-large-priming
+fate-caf-opus-large-priming: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_data 
-show_entries stream=initial_padding,extradata 
$(TARGET_SAMPLES)/caf/opus-large-priming.caf
+
 FATE_SAMPLES_FFMPEG         += $(FATE_CAF_FFMPEG-yes)
 FATE_SAMPLES_FFMPEG_FFPROBE += $(FATE_CAF_FFMPEG_FFPROBE-yes)
-fate-caf: $(FATE_CAF_FFMPEG-yes) $(FATE_CAF_FFMPEG_FFPROBE-yes)
+FATE_SAMPLES_FFPROBE        += $(FATE_CAF_FFPROBE-yes)
+fate-caf: $(FATE_CAF_FFMPEG-yes) $(FATE_CAF_FFMPEG_FFPROBE-yes) 
$(FATE_CAF_FFPROBE-yes)
diff --git a/tests/ref/fate/caf-opus-large-priming 
b/tests/ref/fate/caf-opus-large-priming
new file mode 100644
index 0000000000..4e2d0a531b
--- /dev/null
+++ b/tests/ref/fate/caf-opus-large-priming
@@ -0,0 +1,7 @@
+[STREAM]
+initial_padding=70000
+extradata=
+00000000: 4f70 7573 4865 6164 0102 ffff 80bb 0000  OpusHead........
+00000010: 0000 00                                  ...
+
+[/STREAM]

-- 
To stop receiving notification emails like this one, please contact
[email protected].
_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to