Fixed bug in QWaveDecoder.
authorYoann Lopes <yoann.lopes@digia.com>
Wed, 24 Jul 2013 11:01:08 +0000 (13:01 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Mon, 5 Aug 2013 16:08:53 +0000 (18:08 +0200)
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>
src/multimedia/audio/qwavedecoder_p.cpp

index b75bfaf..497a146 100644 (file)
@@ -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;
 }