Bug 1401066 - Add poison canary to check for errors. r=francois
authorThomas Nguyen <tnguyen@mozilla.com>
Sat, 23 Sep 2017 00:03:22 +0800
changeset 382662 f08155dff5e1a04371b83b27226ee344d613d973
parent 382661 f65c1859b21e0e6fbcfefe0bd918dbea9a36edd0
child 382663 3f384ef139c4217981891b23cdcce8352cab0a0c
push id95388
push usertnguyen@mozilla.com
push dateMon, 25 Sep 2017 02:57:38 +0000
treeherdermozilla-inbound@f08155dff5e1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfrancois
bugs1401066
milestone58.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 1401066 - Add poison canary to check for errors. r=francois MozReview-Commit-ID: GpTDMR5Ni3e
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
@@ -394,16 +394,18 @@ nsUrlClassifierPrefixSet::StoreToFile(ns
   LOG(("Saving PrefixSet successful\n"));
 
   return NS_OK;
 }
 
 nsresult
 nsUrlClassifierPrefixSet::LoadPrefixes(nsIInputStream* in)
 {
+  mCanary.Check();
+
   uint32_t magic;
   uint32_t read;
 
   nsresult rv = in->Read(reinterpret_cast<char*>(&magic), sizeof(uint32_t), &read);
   NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_TRUE(read == sizeof(uint32_t), NS_ERROR_FAILURE);
 
   if (magic == PREFIXSET_VERSION_MAGIC) {
@@ -484,16 +486,18 @@ nsUrlClassifierPrefixSet::CalculatePreal
   fileSize += 2 * mIndexPrefixes.Length() * sizeof(uint32_t);
   fileSize += deltas * sizeof(uint16_t);
   return fileSize;
 }
 
 nsresult
 nsUrlClassifierPrefixSet::WritePrefixes(nsIOutputStream* out)
 {
+  mCanary.Check();
+
   uint32_t written;
   uint32_t writelen = sizeof(uint32_t);
   uint32_t magic = PREFIXSET_VERSION_MAGIC;
   nsresult rv = out->Write(reinterpret_cast<char*>(&magic), writelen, &written);
   NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_TRUE(written == writelen, NS_ERROR_FAILURE);
 
   uint32_t indexSize = mIndexPrefixes.Length();
--- a/toolkit/components/url-classifier/nsUrlClassifierPrefixSet.h
+++ b/toolkit/components/url-classifier/nsUrlClassifierPrefixSet.h
@@ -14,16 +14,17 @@
 #include "nsIMutableArray.h"
 #include "nsIFileStreams.h"
 #include "nsIUrlClassifierPrefixSet.h"
 #include "nsTArray.h"
 #include "nsToolkitCompsCID.h"
 #include "mozilla/FileUtils.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/Mutex.h"
+#include "mozilla/Poison.h"
 
 namespace mozilla {
 namespace safebrowsing {
 
 class VariableLengthPrefixSet;
 
 } // namespace safebrowsing
 } // namespace mozilla
@@ -79,11 +80,12 @@ private:
   // 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;
   // how many prefixes we have.
   uint32_t mTotalPrefixes;
 
   nsCString mMemoryReportPath;
+  mozilla::CorruptionCanary mCanary;
 };
 
 #endif