Bug 1021612 - Fix offset calculation in CacheFileMetadata::ReadMetadata(), r=honzab
authorMichal Novotny <michal.novotny@gmail.com>
Sun, 08 Jun 2014 00:00:57 +0200
changeset 207791 5fa491e07b4bdeb477ad9be4305cfd8ea153531b
parent 207790 7d4ed44d5913845dd8caef21c0d00c7262171549
child 207792 5bd30aa6ace2a514afd213305069218d77db5288
push id494
push userraliiev@mozilla.com
push dateMon, 25 Aug 2014 18:42:16 +0000
treeherdermozilla-release@a3cc3e46b571 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershonzab
bugs1021612
milestone32.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1021612 - Fix offset calculation in CacheFileMetadata::ReadMetadata(), r=honzab
netwerk/cache2/CacheFileMetadata.cpp
--- a/netwerk/cache2/CacheFileMetadata.cpp
+++ b/netwerk/cache2/CacheFileMetadata.cpp
@@ -180,21 +180,27 @@ CacheFileMetadata::ReadMetadata(CacheFil
     LOG(("CacheFileMetadata::ReadMetadata() - File is corrupted, creating "
          "empty metadata. [this=%p, filesize=%lld]", this, size));
 
     InitEmptyMetadata();
     aListener->OnMetadataRead(NS_OK);
     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));
 
   DoMemoryReport(MemoryUsage());
 
   LOG(("CacheFileMetadata::ReadMetadata() - Reading metadata from disk, trying "
        "offset=%lld, filesize=%lld [this=%p]", offset, size, this));