From 1128418e2a6897da9d08c42b2ef02d7d31a2a14c Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Sat, 29 Aug 2020 14:32:47 +0000 Subject: mpeg: fixed xing header parsing for files with CRC protection (#1059) git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@9487 90c681e8-e032-0410-971d-27865f9a5e38 --- src/plugins/Input/mpeg/decoder_mad.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/plugins/Input/mpeg') diff --git a/src/plugins/Input/mpeg/decoder_mad.cpp b/src/plugins/Input/mpeg/decoder_mad.cpp index 59b77c71d..7f3ca4f93 100644 --- a/src/plugins/Input/mpeg/decoder_mad.cpp +++ b/src/plugins/Input/mpeg/decoder_mad.cpp @@ -128,8 +128,23 @@ bool DecoderMAD::findXingHeader(struct mad_bitptr ptr, unsigned int bitlen) return false; quint32 xing_magic = mad_bit_read(&ptr, 32); + bitlen -= 32; + if(xing_magic != XING_MAGIC && xing_magic != XING_MAGIC2) - return false; + { + /* + * Due to an unfortunate historical accident, a Xing VBR tag may be + * misplaced in a stream with CRC protection. We check for this by + * assuming the tag began two octets prior and the high bits of the + * following flags field are always zero. + */ + + if(xing_magic != ((quint64(XING_MAGIC) << 16) & 0xffffffffL) && xing_magic != ((quint64(XING_MAGIC2) << 16) & 0xffffffffL)) + return false; + + mad_bit_skip(&ptr, 16); + bitlen += 16; + } m_xing.flags = mad_bit_read(&ptr, 32); bitlen -= 64; -- cgit v1.2.3-13-gbd6f