Bug 1542744 - P1. Remove calculating checksum for mIndexDelta array. r=gcp
☠☠ backed out by 836dbcf0ffca ☠ ☠
authordlee <dlee@mozilla.com>
Wed, 08 May 2019 08:35:06 +0000
changeset 532654 aedbe6cdd06fdda240d262c366c594a463df71d0
parent 532653 51b73cca09ea7dfe1511bede8409dd2260d404aa
child 532655 c51b622bb1fe7e0d21df71a02c7f07f03f1e46fe
push id11270
push userrgurzau@mozilla.com
push dateWed, 15 May 2019 15:07:19 +0000
treeherdermozilla-beta@571bc76da583 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgcp
bugs1542744, 1362761
milestone68.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 1542744 - P1. Remove calculating checksum for mIndexDelta array. r=gcp The checksum calculating code is used to find the root cause of a crash bug during update(Bug 1362761). Since the algorithm will be update in these series of patches, we don't need to keep it. Differential Revision: https://phabricator.services.mozilla.com/D26667
toolkit/components/url-classifier/nsUrlClassifierPrefixSet.cpp
toolkit/components/url-classifier/nsUrlClassifierPrefixSet.h
--- a/toolkit/components/url-classifier/nsUrlClassifierPrefixSet.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierPrefixSet.cpp
@@ -1,17 +1,16 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsUrlClassifierPrefixSet.h"
 #include "nsIUrlClassifierPrefixSet.h"
-#include "crc32c.h"
 #include "nsCOMPtr.h"
 #include "nsDebug.h"
 #include "nsPrintfCString.h"
 #include "nsTArray.h"
 #include "nsString.h"
 #include "nsTArray.h"
 #include "nsThreadUtils.h"
 #include "nsNetUtil.h"
@@ -30,32 +29,19 @@ static LazyLogModule gUrlClassifierPrefi
 #define LOG(args) \
   MOZ_LOG(gUrlClassifierPrefixSetLog, mozilla::LogLevel::Debug, args)
 #define LOG_ENABLED() \
   MOZ_LOG_TEST(gUrlClassifierPrefixSetLog, mozilla::LogLevel::Debug)
 
 NS_IMPL_ISUPPORTS(nsUrlClassifierPrefixSet, nsIUrlClassifierPrefixSet,
                   nsIMemoryReporter)
 
-template <typename T>
-static void CalculateTArrayChecksum(const nsTArray<T>& aArray,
-                                    uint32_t* outChecksum) {
-  *outChecksum = ~0;
-
-  for (size_t i = 0; i < aArray.Length(); i++) {
-    const T& element = aArray[i];
-    const void* pointer = &element;
-    *outChecksum = ComputeCrc32c(
-        *outChecksum, reinterpret_cast<const uint8_t*>(pointer), sizeof(void*));
-  }
-}
 
 nsUrlClassifierPrefixSet::nsUrlClassifierPrefixSet()
     : mLock("nsUrlClassifierPrefixSet.mLock"),
-      mIndexDeltasChecksum(~0),
       mTotalPrefixes(0) {}
 
 NS_IMETHODIMP
 nsUrlClassifierPrefixSet::Init(const nsACString& aName) {
   mName = aName;
   mMemoryReportPath = nsPrintfCString(
       "explicit/storage/prefix-set/%s",
       (!aName.IsEmpty() ? PromiseFlatCString(aName).get() : "?!"));
@@ -67,17 +53,16 @@ nsUrlClassifierPrefixSet::Init(const nsA
 
 nsUrlClassifierPrefixSet::~nsUrlClassifierPrefixSet() {
   UnregisterWeakMemoryReporter(this);
 }
 
 void nsUrlClassifierPrefixSet::Clear() {
   LOG(("[%s] Clearing PrefixSet", mName.get()));
   mIndexDeltas.Clear();
-  mIndexDeltasChecksum = ~0;
   mIndexPrefixes.Clear();
   mTotalPrefixes = 0;
 }
 
 NS_IMETHODIMP
 nsUrlClassifierPrefixSet::SetPrefixes(const uint32_t* aArray,
                                       uint32_t aLength) {
   MutexAutoLock lock(mLock);
@@ -141,25 +126,21 @@ nsresult nsUrlClassifierPrefixSet::MakeP
     }
     previousItem = aPrefixes[i];
   }
 
   mTotalPrefixes = aLength;
 
   mIndexDeltas.LastElement().Compact();
 
-  // The hdr pointer of the last element of nsTArray may change after calling
-  // mIndexDeltas.LastElement().Compact(), so calculate checksum after the call.
-  CalculateTArrayChecksum(mIndexDeltas, &mIndexDeltasChecksum);
-
   mIndexDeltas.Compact();
   mIndexPrefixes.Compact();
   MOZ_ASSERT(mIndexPrefixes.Length() == mIndexDeltas.Length());
 
-  LOG(("Total number of indices: %d (crc=%u)", aLength, mIndexDeltasChecksum));
+  LOG(("Total number of indices: %d", aLength));
   LOG(("Total number of deltas: %d", totalDeltas));
   LOG(("Total number of delta chunks: %zu", mIndexDeltas.Length()));
 
   return NS_OK;
 }
 
 nsresult nsUrlClassifierPrefixSet::GetPrefixesNative(
     FallibleTArray<uint32_t>& outArray) {
@@ -438,29 +419,16 @@ uint32_t nsUrlClassifierPrefixSet::Calcu
 }
 
 nsresult nsUrlClassifierPrefixSet::WritePrefixes(
     nsCOMPtr<nsIOutputStream>& out) const {
   MutexAutoLock lock(mLock);
 
   mCanary.Check();
 
-  // In Bug 1362761, crashes happened while reading mIndexDeltas[i].
-  // We suspect that this is due to memory corruption so to test this
-  // hypothesis, we will crash the browser. Once we have established
-  // memory corruption as the root cause, we can attempt to gracefully
-  // handle this.
-  uint32_t checksum;
-  CalculateTArrayChecksum(mIndexDeltas, &checksum);
-  if (checksum != mIndexDeltasChecksum) {
-    LOG(("[%s] The contents of mIndexDeltas doesn't match the checksum!",
-         mName.get()));
-    MOZ_CRASH("Memory corruption detected in mIndexDeltas.");
-  }
-
   uint32_t written;
   uint32_t writelen = sizeof(uint32_t);
   const uint32_t magic = PREFIXSET_VERSION_MAGIC;
   nsresult rv =
       out->Write(reinterpret_cast<const char*>(&magic), writelen, &written);
   NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_TRUE(written == writelen, NS_ERROR_FAILURE);
 
--- a/toolkit/components/url-classifier/nsUrlClassifierPrefixSet.h
+++ b/toolkit/components/url-classifier/nsUrlClassifierPrefixSet.h
@@ -72,17 +72,16 @@ class nsUrlClassifierPrefixSet final : p
   // list of fully stored prefixes, that also form the
   // start of a run of deltas in mIndexDeltas.
   nsTArray<uint32_t> mIndexPrefixes;
   // array containing arrays of deltas from indices.
   // Index to the place that matches the closest lower
   // prefix from mIndexPrefix. Then every "delta" corresponds
   // to a prefix in the PrefixSet.
   nsTArray<nsTArray<uint16_t> > mIndexDeltas;
-  uint32_t mIndexDeltasChecksum;
 
   // how many prefixes we have.
   uint32_t mTotalPrefixes;
 
   nsCString mName;
   nsCString mMemoryReportPath;
   mozilla::CorruptionCanary mCanary;
 };