diff --git a/netwerk/cache2/CacheFileMetadata.cpp b/netwerk/cache2/CacheFileMetadata.cpp index 91216b308a6..dc49137ada2 100644 --- a/netwerk/cache2/CacheFileMetadata.cpp +++ b/netwerk/cache2/CacheFileMetadata.cpp @@ -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(moz_xmalloc(mBufSize));