diff mbox

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

Message ID CAPUDrwc+g7=TnKZAYFyZJYVYTZ4Rcx4PeUYs7G=9j_z3Miw0_Q@mail.gmail.com
State Superseded
Headers show

Commit Message

Dale Curtis Feb. 23, 2018, 6:37 p.m. UTC
After some deeper testing it looks like this mechanism can actually fully
replace the existing ID3 and APE tag skips; so I've simplified the patch to
do so.

- dale

On Thu, Feb 22, 2018 at 4:46 PM, Dale Curtis <dalecurtis@chromium.org>
wrote:

> 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 f911dcfcb059e4d439a7ba74417fcb92a4079ae9 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 | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/libavcodec/mpegaudio_parser.c b/libavcodec/mpegaudio_parser.c
index 244281b56f..f68b26d238 100644
--- a/libavcodec/mpegaudio_parser.c
+++ b/libavcodec/mpegaudio_parser.c
@@ -23,8 +23,6 @@ 
 #include "parser.h"
 #include "mpegaudiodecheader.h"
 #include "libavutil/common.h"
-#include "libavformat/apetag.h" // for APE tag.
-#include "libavformat/id3v1.h" // for ID3v1_TAG_SIZE
 
 typedef struct MpegAudioParseContext {
     ParseContext pc;
@@ -115,13 +113,8 @@  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) {
+    if (flush && !s->frame_size) {
+        av_log(avctx, AV_LOG_WARNING, "Discarding invalid trailing data from mpeg audio stream.\n");
         *poutbuf = NULL;
         *poutbuf_size = 0;
         return next;
-- 
2.16.1.291.g4437f3f132-goog