From f01af490a0be13219deb0499c210ceee700332ba Mon Sep 17 00:00:00 2001 From: Yoann Lopes Date: Wed, 24 Jul 2013 13:01:08 +0200 Subject: [PATCH] Fixed bug in QWaveDecoder. When looking for a specific chunk, it was entering an infinite loop if not finding it in the next two chunks available. It now correctly tries to find the chunk until it reaches the end of the IO device. Change-Id: I29252318566fe3a47f267410c91dacaf302d9618 Reviewed-by: Andy Nichols --- src/multimedia/audio/qwavedecoder_p.cpp | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/multimedia/audio/qwavedecoder_p.cpp b/src/multimedia/audio/qwavedecoder_p.cpp index b75bfaf..497a146 100644 --- a/src/multimedia/audio/qwavedecoder_p.cpp +++ b/src/multimedia/audio/qwavedecoder_p.cpp @@ -244,16 +244,18 @@ bool QWaveDecoder::enoughDataAvailable() bool QWaveDecoder::findChunk(const char *chunkId) { chunk descriptor; - if (!peekChunk(&descriptor)) - return false; - if (qstrncmp(descriptor.id, chunkId, 4) == 0) - return true; + do { + if (!peekChunk(&descriptor)) + return false; + + if (qstrncmp(descriptor.id, chunkId, 4) == 0) + return true; + + // It's possible that bytes->available() is less than the chunk size + // if it's corrupt. + junkToSkip = qint64(sizeof(chunk) + descriptor.size); - // It's possible that bytes->available() is less than the chunk size - // if it's corrupt. - junkToSkip = qint64(sizeof(chunk) + descriptor.size); - while (source->bytesAvailable() > 0) { // Skip the current amount if (junkToSkip > 0) discardBytes(junkToSkip); @@ -263,12 +265,7 @@ bool QWaveDecoder::findChunk(const char *chunkId) if (junkToSkip > 0) return false; - if (!peekChunk(&descriptor)) - return false; - - if (qstrncmp(descriptor.id, chunkId, 4) == 0) - return true; - } + } while (source->bytesAvailable() > 0); return false; } -- 2.7.4