PR #25860 opened by Jun Zhao (mypopydev)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25860
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25860.patch

When the best header has no child, get_best_header() returns everything
from that header to the end of the FIFO. flac_parse() then frees the best
header but keeps best_header->next and leaves the FIFO undrained, so the
next flush call promotes a false sync found inside the frame just returned
and emits its leading bytes a second time as a junk packet, which the
decoder rejects.

When end_padded is set, no further input can arrive and the frame just
returned already consumed the rest of the FIFO. Free any remaining
headers and drain the FIFO.

Unlike 2d7eacee24, this covers false syncs whose blocking strategy agrees
with STREAMINFO, since that check cannot reject a fixed-blocksize false
sync in a fixed-blocksize stream.

Fixes: https://code.ffmpeg.org/FFmpeg/FFmpeg/issues/25857
See: https://code.ffmpeg.org/FFmpeg/FFmpeg/issues/25766
Signed-off-by: Jun Zhao <[email protected]>

# Summary of changes

Briefly describe what this PR does and why.

<!--
If this PR requires new FATE test samples, attach them to the PR and
list their target paths below (relative to the fate-suite root).

Attached filenames must match the sample's filename:

```fate-samples
# e.g. vorbis/new-sample.ogg
```
-->



>From 066d79af16bf6a582c9d12ce6c57630f38a3e19e Mon Sep 17 00:00:00 2001
From: Jun Zhao <[email protected]>
Date: Sun, 8 Nov 2026 20:44:46 +0800
Subject: [PATCH] avcodec/flac_parser: drop leftover headers when flushing at
 EOF

When the best header has no child, get_best_header() returns everything
from that header to the end of the FIFO. flac_parse() then frees the best
header but keeps best_header->next and leaves the FIFO undrained, so the
next flush call promotes a false sync found inside the frame just returned
and emits its leading bytes a second time as a junk packet, which the
decoder rejects.

When end_padded is set, no further input can arrive and the frame just
returned already consumed the rest of the FIFO. Free any remaining
headers and drain the FIFO.

Unlike 2d7eacee24, this covers false syncs whose blocking strategy agrees
with STREAMINFO, since that check cannot reject a fixed-blocksize false
sync in a fixed-blocksize stream.

Fixes: https://code.ffmpeg.org/FFmpeg/FFmpeg/issues/25857
See: https://code.ffmpeg.org/FFmpeg/FFmpeg/issues/25766
Signed-off-by: Jun Zhao <[email protected]>
---
 libavcodec/flac_parser.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/libavcodec/flac_parser.c b/libavcodec/flac_parser.c
index 8ee7439f7c3..1dfe80505bd 100644
--- a/libavcodec/flac_parser.c
+++ b/libavcodec/flac_parser.c
@@ -795,6 +795,21 @@ static int flac_parse(AVCodecParserContext *s, 
AVCodecContext *avctx,
             fpc->headers->prev = NULL;
         av_freep(&fpc->best_header);
         fpc->nb_headers_buffered--;
+
+        /* Without a child, get_best_header() already returned everything
+         * from this header to the end of the FIFO. At EOF there can be no
+         * further frames, so any header still queued is a false sync inside
+         * that frame. Drop them and drain the FIFO, or the next flush emits
+         * part of the final frame a second time. */
+        if (fpc->end_padded) {
+            for (curr = fpc->headers; curr; curr = temp) {
+                temp = curr->next;
+                av_free(curr);
+                fpc->nb_headers_buffered--;
+            }
+            fpc->headers = NULL;
+            flac_fifo_drain(&fpc->fifo_buf, flac_fifo_size(&fpc->fifo_buf));
+        }
     }
 
     /* Find and score new headers.                                     */
-- 
2.54.0

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

Reply via email to