From ff28a947df32728be80c7739e377bcb3ea43861f Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Sun, 22 Jul 2018 08:51:00 +0000 Subject: sndfile: fixed issue with 'JUNK' and 'bext' chunks (#970) git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@8207 90c681e8-e032-0410-971d-27865f9a5e38 --- .../Input/sndfile/decodersndfilefactory.cpp | 36 ++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/Input/sndfile/decodersndfilefactory.cpp b/src/plugins/Input/sndfile/decodersndfilefactory.cpp index d2cedb38c..7097fd87e 100644 --- a/src/plugins/Input/sndfile/decodersndfilefactory.cpp +++ b/src/plugins/Input/sndfile/decodersndfilefactory.cpp @@ -38,13 +38,45 @@ // DecoderSndFileFactory bool DecoderSndFileFactory::canDecode(QIODevice *input) const { - char buf[36]; + char buf[36] = {0}; if(input->peek(buf, sizeof(buf)) != sizeof(buf)) return false; if(!memcmp(buf + 8, "WAVE", 4) && (!memcmp(buf, "RIFF", 4) || !memcmp(buf, "RIFX", 4))) { - quint16 subformat = (quint16(buf[21]) << 8) + buf[20]; + quint16 subformat = 0; + + if(!memcmp(buf + 12, "fmt ", 4)) + { + subformat = (quint16(buf[21]) << 8) + buf[20]; + } + else if(!input->isSequential()) + { + input->seek(12); + //skip "JUNK" and "bext" chunks + while(!input->atEnd()) + { + if(input->peek(buf, sizeof(buf)) != sizeof(buf)) + return false; + + if(!memcmp(buf, "fmt ", 4)) + { + subformat = (quint16(buf[9]) << 8) + buf[8]; + break; + } + else if(!memcmp(buf, "JUNK", 4) || !memcmp(buf, "bext", 4)) + { + size_t size = buf[4] + (buf[5] << 8) + (buf[6] << 16) + (buf[7] << 24); + if(!input->seek(input->pos() + size + 8)) + break; + } + else + { + break; + } + } + input->seek(0); + } switch (subformat) { -- cgit v1.2.3-13-gbd6f