[PR] avcodec/aac_ac3_parser: drop leading garbage before the first valid frame (PR #24250)
Kacper Michajłow via ffmpeg-devel <[email protected]>
| Newsgroups | gmane.comp.video.ffmpeg.devel |
|---|---|
| Message-ID | <[email protected]> |
PR #24250 opened by Kacper Michajłow (kasper93) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24250 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24250.patch When the parser starts mid-stream, e.g. after a seek, the data before the first (E-)AC-3 syncword is a partial frame tail that can itself contain syncword-like byte patterns. Such a chunk fails header or CRC validation, but was still returned as a packet, making decoder unhappy. Suppress the output only until the first validated frame. After that, failed validation keeps outputting as before, so genuinely damaged streams still reach the decoder and its error concealment. From e8c2bc60c664901fcb489199f27557ade166e29f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= <[email protected]> Date: Sun, 23 Aug 2026 20:16:57 +0200 Subject: [PATCH] avcodec/aac_ac3_parser: drop leading garbage before the first valid frame MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the parser starts mid-stream, e.g. after a seek, the data before the first (E-)AC-3 syncword is a partial frame tail that can itself contain syncword-like byte patterns. Such a chunk fails header or CRC validation, but was still returned as a packet, making decoder unhappy. Suppress the output only until the first validated frame. After that, failed validation keeps outputting as before, so genuinely damaged streams still reach the decoder and its error concealment. Signed-off-by: Kacper Michajłow <[email protected]> --- libavcodec/aac_ac3_parser.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libavcodec/aac_ac3_parser.c b/libavcodec/aac_ac3_parser.c index 51c801214c..f90c159ff9 100644 --- a/libavcodec/aac_ac3_parser.c +++ b/libavcodec/aac_ac3_parser.c @@ -102,7 +102,7 @@ get_next: int offset = ff_ac3_find_syncword(buf, buf_size); if (offset < 0) - return i; + goto invalid; buf += offset; buf_size -= offset; @@ -110,7 +110,7 @@ get_next: int ret = avpriv_ac3_parse_header(&phrd, buf, buf_size); if (ret < 0 || hdr.frame_size > buf_size) - return i; + goto invalid; if (buf_size > hdr.frame_size) { buf += hdr.frame_size; @@ -120,7 +120,7 @@ get_next: /* Check for false positives since the syncword is not enough. See section 6.1.2 of A/52. */ if (av_crc(s->crc_ctx, 0, buf + 2, hdr.frame_size - 2)) - return i; + goto invalid; break; } @@ -169,4 +169,13 @@ get_next: } return i; + +#if CONFIG_AC3_PARSER +invalid: + if (!s->frame_number) { + *poutbuf = NULL; + *poutbuf_size = 0; + } + return i; +#endif } -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]