Bug 497815 - Read Wave headers in small chunks to avoid unnecessary large allocations. r=roc

--HG--
extra : rebase_source : 355af524b6d9f0634d9d09e4ddc1ce1715bc6c81
This commit is contained in:
Matthew Gregan 2009-09-07 15:28:26 +12:00
parent 6174ee7312
commit 658839d732

View File

@ -976,19 +976,23 @@ nsWaveStateMachine::ScanForwardUntil(PRUint32 aWantedChunk, PRUint32* aChunkSize
}
PRUint32 magic = ReadUint32BE(&p);
PRUint32 size = ReadUint32LE(&p);
PRUint32 chunkSize = ReadUint32LE(&p);
if (magic == aWantedChunk) {
*aChunkSize = size;
*aChunkSize = chunkSize;
return PR_TRUE;
}
// RIFF chunks are two-byte aligned, so round up if necessary.
size += size % 2;
chunkSize += chunkSize % 2;
nsAutoArrayPtr<char> chunk(new char[size]);
if (!ReadAll(chunk.get(), size)) {
return PR_FALSE;
while (chunkSize > 0) {
PRUint32 size = PR_MIN(chunkSize, 1 << 16);
nsAutoArrayPtr<char> chunk(new char[size]);
if (!ReadAll(chunk.get(), size)) {
return PR_FALSE;
}
chunkSize -= size;
}
}
}