diff mbox

[FFmpeg-devel,mpegaudio_parser] Skip trailing junk data when flushing parser.

Message ID CAPUDrwdqiCcDEvHUt7vfOH_tSzjaAuki5q9stt7=ecwmfjWzRQ@mail.gmail.com
State Superseded
Headers show

Commit Message

Dale Curtis Feb. 23, 2018, 12:46 a.m. UTC
The parser should only return valid mpeg audio packets; it generally
does so, but in the case of flush, it returns whatever happens to
be in the buffer instead of ensuring its first a valid mpeg packet.

The fix is to check whether a valid frame size has been parsed and
if not discard the packet when flushing.

This should fix all sorts of mp3 files with trailing garbage.

Signed-off-by: Dale Curtis <dalecurtis@chromium.org>
diff mbox

Patch

From 1ede24ef6a0992dace2b86bd333cfd8044e64b93 Mon Sep 17 00:00:00 2001
From: Dale Curtis <dalecurtis@chromium.org>
Date: Thu, 22 Feb 2018 16:43:37 -0800
Subject: [PATCH] [mpegaudio_parser] Skip trailing junk data when flushing
 parser.

The parser should only return valid mpeg audio packets; it generally
does so, but in the case of flush, it returns whatever happens to
be in the buffer instead of ensuring its first a valid mpeg packet.

The fix is to check whether a valid frame size has been parsed and
if not discard the packet when flushing.

This should fix all sorts of mp3 files with trailing garbage.

Signed-off-by: Dale Curtis <dalecurtis@chromium.org>
---
 libavcodec/mpegaudio_parser.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/libavcodec/mpegaudio_parser.c b/libavcodec/mpegaudio_parser.c
index 244281b56f..c6d843cd9f 100644
--- a/libavcodec/mpegaudio_parser.c
+++ b/libavcodec/mpegaudio_parser.c
@@ -115,16 +115,17 @@  static int mpegaudio_parse(AVCodecParserContext *s1,
         return buf_size;
     }
 
-    if (flush && buf_size >= ID3v1_TAG_SIZE && memcmp(buf, "TAG", 3) == 0) {
-        *poutbuf = NULL;
-        *poutbuf_size = 0;
-        return next;
-    }
-
-    if (flush && buf_size >= APE_TAG_FOOTER_BYTES && memcmp(buf, APE_TAG_PREAMBLE, 8) == 0) {
-        *poutbuf = NULL;
-        *poutbuf_size = 0;
-        return next;
+    if (flush) {
+        if (!s->frame_size)
+            av_log(avctx, AV_LOG_DEBUG, "Discarding invalid trailing data.\n");
+
+        if (!s->frame_size ||
+            (buf_size >= ID3v1_TAG_SIZE && memcmp(buf, "TAG", 3) == 0) ||
+            (buf_size >= APE_TAG_FOOTER_BYTES && memcmp(buf, APE_TAG_PREAMBLE, 8) == 0)) {
+            *poutbuf = NULL;
+            *poutbuf_size = 0;
+            return next;
+        }
     }
 
     *poutbuf = buf;
-- 
2.16.1.291.g4437f3f132-goog