Commit bb2879b5a0 for ffmpeg

commit bb2879b5a0960428deda5dcbf3c2c2d6c41646e0
Author: Romain Beauxis <romain.beauxis@gmail.com>
Date:   Thu Nov 26 20:41:06 2026 -0600

    avformat/ogg/muxer/opus: reject identification headers larger than a page

    The identification header completes the first page of an Opus stream
    (RFC 7845, section 3), so one of a page or more cannot be written. One
    filling all 255 lacing values ends the page while it is buffered: set
    the BOS flag before buffering it, and do not end the page again once it
    is empty.

diff --git a/libavformat/ogg/muxer.c b/libavformat/ogg/muxer.c
index ac775a2381..e1eb8a21a2 100644
--- a/libavformat/ogg/muxer.c
+++ b/libavformat/ogg/muxer.c
@@ -480,13 +480,14 @@ static int ogg_write_header(AVFormatContext *s)

     for (j = 0; j < s->nb_streams; j++) {
         oggstream = s->streams[j]->priv_data;
+        oggstream->page.flags |= 2; // bos
         ret = ogg_buffer_data(s, s->streams[j], oggstream->header[0],
                               oggstream->header_len[0], 0, 1);
         if (ret < 0)
             return ret;
-        oggstream->page.flags |= 2; // bos
-        ret = ogg_buffer_page(s, oggstream);
-        if (ret < 0)
+        /* 255 lacing values end the page within ogg_buffer_data(). */
+        if (oggstream->page.segments_count &&
+            (ret = ogg_buffer_page(s, oggstream)) < 0)
             return ret;
     }
     for (j = 0; j < s->nb_streams; j++) {
diff --git a/libavformat/ogg/muxer/opus.c b/libavformat/ogg/muxer/opus.c
index de1c891131..45e483c394 100644
--- a/libavformat/ogg/muxer/opus.c
+++ b/libavformat/ogg/muxer/opus.c
@@ -36,7 +36,9 @@ static int opus_build_headers(AVCodecParameters *par,
 {
     uint8_t *p;

-    if (par->extradata_size < OPUS_HEADER_SIZE)
+    /* The identification header is alone on the first page, which it must
+     * complete. */
+    if (par->extradata_size < OPUS_HEADER_SIZE || par->extradata_size >= MAX_PAGE_SIZE)
         return AVERROR_INVALIDDATA;

     /* first packet: Opus header */