Bug 1021612 - Fix offset calculation in CacheFileMetadata::ReadMetadata(), r=honzab

This commit is contained in:
Michal Novotny 2014-06-08 00:00:57 +02:00
parent 8f6948b38d
commit 6266244a13

View File

@ -185,11 +185,17 @@ CacheFileMetadata::ReadMetadata(CacheFileMetadataListener *aListener)
return NS_OK;
}
// round offset to 4k blocks
int64_t offset = (size / kAlignSize) * kAlignSize;
// Set offset so that we read at least kMinMetadataRead if the file is big
// enough.
int64_t offset;
if (size < kMinMetadataRead) {
offset = 0;
} else {
offset = size - kMinMetadataRead;
}
if (size - offset < kMinMetadataRead && offset > kAlignSize)
offset -= kAlignSize;
// round offset to kAlignSize blocks
offset = (offset / kAlignSize) * kAlignSize;
mBufSize = size - offset;
mBuf = static_cast<char *>(moz_xmalloc(mBufSize));