Bug 1038554 - fix potential wrong file offset calculation in CacheIndex::ParseRecords() and CacheIndex::ParseJournal(), r=honzab
authorMichal Novotny <michal.novotny@gmail.com>
Sat, 10 Jan 2015 01:21:04 +0100
changeset 223092 2ba79118e686b4455ac8dafe8206bfa0358296d4
parent 223091 be02b84dfca41dff53ab1e54a44ce0373b19168a
child 223093 9739ef7c3d2f6ae43c7020b107666327f865580d
push id28082
push usercbook@mozilla.com
push dateMon, 12 Jan 2015 10:44:52 +0000
treeherdermozilla-central@643589c3ef94 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershonzab
bugs1038554
milestone37.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 1038554 - fix potential wrong file offset calculation in CacheIndex::ParseRecords() and CacheIndex::ParseJournal(), r=honzab
netwerk/cache2/CacheIndex.cpp
--- a/netwerk/cache2/CacheIndex.cpp
+++ b/netwerk/cache2/CacheIndex.cpp
@@ -2196,20 +2196,21 @@ CacheIndex::ParseRecords()
     pos += sizeof(CacheIndexRecord);
     mSkipEntries++;
   }
 
   mRWHash->Update(mRWBuf + hashOffset, pos - hashOffset);
 
   if (pos != mRWBufPos) {
     memmove(mRWBuf, mRWBuf + pos, mRWBufPos - pos);
-    mRWBufPos -= pos;
-    pos = 0;
   }
 
+  mRWBufPos -= pos;
+  pos = 0;
+
   int64_t fileOffset = sizeof(CacheIndexHeader) +
                        mSkipEntries * sizeof(CacheIndexRecord) + mRWBufPos;
 
   MOZ_ASSERT(fileOffset <= mIndexHandle->FileSize());
   if (fileOffset == mIndexHandle->FileSize()) {
     if (mRWHash->GetHash() != NetworkEndian::readUint32(mRWBuf)) {
       LOG(("CacheIndex::ParseRecords() - Hash mismatch, [is %x, should be %x]",
            mRWHash->GetHash(),
@@ -2281,17 +2282,17 @@ CacheIndex::StartReadingJournal()
          " synchronously [rv=0x%08x]", rv));
     FinishRead(false);
   }
 }
 
 void
 CacheIndex::ParseJournal()
 {
-  LOG(("CacheIndex::ParseRecords()"));
+  LOG(("CacheIndex::ParseJournal()"));
 
   nsresult rv;
 
   AssertOwnsLock();
 
   uint32_t entryCnt = (mJournalHandle->FileSize() -
                        sizeof(CacheHash::Hash32_t)) / sizeof(CacheIndexRecord);
 
@@ -2317,20 +2318,21 @@ CacheIndex::ParseJournal()
     pos += sizeof(CacheIndexRecord);
     mSkipEntries++;
   }
 
   mRWHash->Update(mRWBuf, pos);
 
   if (pos != mRWBufPos) {
     memmove(mRWBuf, mRWBuf + pos, mRWBufPos - pos);
-    mRWBufPos -= pos;
-    pos = 0;
   }
 
+  mRWBufPos -= pos;
+  pos = 0;
+
   int64_t fileOffset = mSkipEntries * sizeof(CacheIndexRecord) + mRWBufPos;
 
   MOZ_ASSERT(fileOffset <= mJournalHandle->FileSize());
   if (fileOffset == mJournalHandle->FileSize()) {
     if (mRWHash->GetHash() != NetworkEndian::readUint32(mRWBuf)) {
       LOG(("CacheIndex::ParseJournal() - Hash mismatch, [is %x, should be %x]",
            mRWHash->GetHash(),
            NetworkEndian::readUint32(mRWBuf)));