Bug 730425 - Make range check assertion in stream read fatal, and add the same check to similar code in the cached stream read. r=roc

This commit is contained in:
Matthew Gregan 2012-03-01 12:52:02 +13:00
parent 602d2c3be1
commit 83e74f7378

View File

@ -2226,7 +2226,7 @@ nsMediaCacheStream::Read(char* aBuffer, PRUint32 aCount, PRUint32* aBytes)
gMediaCache->NoteBlockUsage(this, cacheBlock, mCurrentMode, TimeStamp::Now());
PRInt64 offset = cacheBlock*BLOCK_SIZE + offsetInStreamBlock;
NS_ASSERTION(size >= 0 && size <= PR_INT32_MAX, "Size out of range.");
NS_ABORT_IF_FALSE(size >= 0 && size <= PR_INT32_MAX, "Size out of range.");
nsresult rv = gMediaCache->ReadCacheFile(offset, aBuffer + count, PRInt32(size), &bytes);
if (NS_FAILED(rv)) {
if (count == 0)
@ -2265,7 +2265,7 @@ nsMediaCacheStream::ReadFromCache(char* aBuffer,
PRUint32 streamBlock = PRUint32(streamOffset/BLOCK_SIZE);
PRUint32 offsetInStreamBlock =
PRUint32(streamOffset - streamBlock*BLOCK_SIZE);
PRInt32 size = NS_MIN<PRInt64>(aCount - count, BLOCK_SIZE - offsetInStreamBlock);
PRInt64 size = NS_MIN<PRInt64>(aCount - count, BLOCK_SIZE - offsetInStreamBlock);
if (mStreamLength >= 0) {
// Don't try to read beyond the end of the stream
@ -2273,7 +2273,9 @@ nsMediaCacheStream::ReadFromCache(char* aBuffer,
if (bytesRemaining <= 0) {
return NS_ERROR_FAILURE;
}
size = NS_MIN(size, PRInt32(bytesRemaining));
size = NS_MIN(size, bytesRemaining);
// Clamp size until 64-bit file size issues (bug 500784) are fixed.
size = NS_MIN(size, PRInt64(PR_INT32_MAX));
}
PRInt32 bytes;
@ -2292,7 +2294,8 @@ nsMediaCacheStream::ReadFromCache(char* aBuffer,
return NS_ERROR_FAILURE;
}
PRInt64 offset = cacheBlock*BLOCK_SIZE + offsetInStreamBlock;
nsresult rv = gMediaCache->ReadCacheFile(offset, aBuffer + count, size, &bytes);
NS_ABORT_IF_FALSE(size >= 0 && size <= PR_INT32_MAX, "Size out of range.");
nsresult rv = gMediaCache->ReadCacheFile(offset, aBuffer + count, PRInt32(size), &bytes);
if (NS_FAILED(rv)) {
return rv;
}