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 <andy.nichols@digia.com>
This commit is contained in:
Yoann Lopes
2013-07-24 13:01:08 +02:00
committed by The Qt Project
parent edc76ed071
commit f01af490a0

View File

@@ -244,16 +244,18 @@ bool QWaveDecoder::enoughDataAvailable()
bool QWaveDecoder::findChunk(const char *chunkId) bool QWaveDecoder::findChunk(const char *chunkId)
{ {
chunk descriptor; chunk descriptor;
if (!peekChunk(&descriptor))
return false;
if (qstrncmp(descriptor.id, chunkId, 4) == 0) do {
return true; 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 // Skip the current amount
if (junkToSkip > 0) if (junkToSkip > 0)
discardBytes(junkToSkip); discardBytes(junkToSkip);
@@ -263,12 +265,7 @@ bool QWaveDecoder::findChunk(const char *chunkId)
if (junkToSkip > 0) if (junkToSkip > 0)
return false; return false;
if (!peekChunk(&descriptor)) } while (source->bytesAvailable() > 0);
return false;
if (qstrncmp(descriptor.id, chunkId, 4) == 0)
return true;
}
return false; return false;
} }