Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: ruikai via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: ruikai <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PR] avcodec/opus/enc: fix overlap buffer seed for first CELT frame (PR #21629)
Date: Mon, 02 Feb 2026 19:24:16 -0000
Message-ID: <177006025674.25.3629336070323473091@4457048688e7> (raw)

PR #21629 opened by ruikai
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21629
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21629.patch

The overlap seed copy in celt_frame_setup_input() used cur->nb_samples
as the copy length, which can be 960 with the default opus_delay. This
overran the 120 sample overlap buffer and scribbled into samples[].

Clamp the copy to CELT_OVERLAP, copy the tail of the previous frame
(the last 120 samples), and zero pad any remainder when the frame is
shorter than the overlap size.

This prevents the OOB write.


>From 6f52fab4e2da9643d8d4ea0932b48ceb061feea6 Mon Sep 17 00:00:00 2001
From: Ruikai Peng <ruikai@pwno.io>
Date: Mon, 2 Feb 2026 14:15:38 -0500
Subject: [PATCH] avcodec/opus/enc: fix overlap buffer seed for first CELT
 frame

The overlap seed copy in celt_frame_setup_input() used cur->nb_samples
as the copy length, which can be 960 with the default opus_delay. This
overran the 120 sample overlap buffer and scribbled into samples[].

Clamp the copy to CELT_OVERLAP, copy the tail of the previous frame
(the last 120 samples), and zero pad any remainder when the frame is
shorter than the overlap size.

This prevents the OOB write.
---
 libavcodec/opus/enc.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/libavcodec/opus/enc.c b/libavcodec/opus/enc.c
index 65e6a09575..462c7d6d77 100644
--- a/libavcodec/opus/enc.c
+++ b/libavcodec/opus/enc.c
@@ -132,7 +132,13 @@ static void celt_frame_setup_input(OpusEncContext *s, CeltFrame *f)
         CeltBlock *b = &f->block[ch];
         const void *input = cur->extended_data[ch];
         size_t bps = av_get_bytes_per_sample(cur->format);
-        memcpy(b->overlap, input, bps*cur->nb_samples);
+        const int overlap_len = FFMIN(cur->nb_samples, CELT_OVERLAP);
+        const size_t overlap_off = (cur->nb_samples - overlap_len) * bps;
+        memcpy(b->overlap, (const uint8_t *)input + overlap_off,
+               bps * overlap_len);
+        if (overlap_len < CELT_OVERLAP)
+            memset(b->overlap + overlap_len, 0,
+                   (CELT_OVERLAP - overlap_len) * sizeof(*b->overlap));
     }
 
     av_frame_free(&cur);
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

                 reply	other threads:[~2026-02-02 19:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=177006025674.25.3629336070323473091@4457048688e7 \
    --to=ffmpeg-devel@ffmpeg.org \
    --cc=code@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git