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(-)
@@ -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