Bug 1311361 - Crash in mozilla::net::CacheFileChunkBuffer::SetDataSize, r=honzab

This commit is contained in:
Michal Novotny 2016-10-24 20:47:56 +02:00
parent 125365b7da
commit f3ecdc91f2

View File

@ -118,8 +118,16 @@ void
CacheFileChunkBuffer::SetDataSize(uint32_t aDataSize)
{
MOZ_RELEASE_ASSERT(
mDataSize <= mBufSize ||
(mBufSize == 0 && mChunk->mState == CacheFileChunk::READING));
// EnsureBufSize must be called before SetDataSize, so the new data size
// is guaranteed to be smaller than or equal to mBufSize.
aDataSize <= mBufSize ||
// The only exception is an optimization when we read the data from the
// disk. The data is read to a separate buffer and CacheFileChunk::mBuf is
// empty (see CacheFileChunk::Read). We need to set mBuf::mDataSize
// accordingly so that DataSize() methods return correct value, but we don't
// want to allocate the buffer since it wouldn't be used in most cases.
(mDataSize == 0 && mBufSize == 0 && mChunk->mState == CacheFileChunk::READING));
mDataSize = aDataSize;
}