Bug 1544598 - Part 0: fix assertion when EncodedSnapshot with an unknown origin; r=chutten
authorLiang-Heng Chen <xeonchen@gmail.com>
Thu, 02 May 2019 15:16:15 +0000
changeset 531443 9a2bdd58f6c6e3614ee7a32fcc7f2c78901308f7
parent 531442 5c493140403539373c1b2b04b75f49255146e72c
child 531444 ce18611e1dd4f9891a4d410bfedc11dc73c4f5e6
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschutten
bugs1544598
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 1544598 - Part 0: fix assertion when EncodedSnapshot with an unknown origin; r=chutten Differential Revision: https://phabricator.services.mozilla.com/D29670
toolkit/components/telemetry/core/TelemetryOrigin.cpp
toolkit/components/telemetry/tests/gtest/TestOrigins.cpp
--- a/toolkit/components/telemetry/core/TelemetryOrigin.cpp
+++ b/toolkit/components/telemetry/core/TelemetryOrigin.cpp
@@ -203,34 +203,34 @@ nsresult AppEncodeTo(const StaticMutexAu
       metricData.SetLength(gPrioDatasPerMetric);
       for (size_t i = 0; i < metricData.Length() - 1; ++i) {
         metricData[i].SetLength(PrioEncoder::gNumBooleans);
         for (auto& metricDatum : metricData[i]) {
           metricDatum = false;
         }
       }
       auto& lastArray = metricData[metricData.Length() - 1];
-      lastArray.SetLength(gOriginHashesList->Length() %
+      lastArray.SetLength((gOriginHashesList->Length() + kNumMetaOrigins) %
                           PrioEncoder::gNumBooleans);
       for (auto& metricDatum : lastArray) {
         metricDatum = false;
       }
 
       auto originIt = bag.ConstIter();
       for (; !originIt.Done(); originIt.Next()) {
         uint32_t originCount = originIt.Data();
         if (originCount >= generation) {
           maxGeneration = std::max(maxGeneration, originCount);
 
           const nsACString& origin = originIt.Key();
           size_t index;
           if (!gOriginToIndexMap->Get(origin, &index)) {
             return NS_ERROR_FAILURE;
           }
-          MOZ_ASSERT(index < gOriginHashesList->Length());
+          MOZ_ASSERT(index < (gOriginHashesList->Length() + kNumMetaOrigins));
           size_t shardIndex = index / PrioEncoder::gNumBooleans;
           MOZ_ASSERT(shardIndex < metricData.Length());
           MOZ_ASSERT(index % PrioEncoder::gNumBooleans <
                      metricData[shardIndex].Length());
           metricData[shardIndex][index % PrioEncoder::gNumBooleans] = true;
         }
       }
       aResult.AppendElement(MakePair(id, metricData));
--- a/toolkit/components/telemetry/tests/gtest/TestOrigins.cpp
+++ b/toolkit/components/telemetry/tests/gtest/TestOrigins.cpp
@@ -178,19 +178,21 @@ TEST_F(TelemetryTestFixture, RecordUnkno
 
 TEST_F(TelemetryTestFixture, EncodedSnapshot) {
   AutoJSContextWithGlobal cx(mCleanGlobal);
   JSContext* aCx = cx.GetJSContext();
 
   Unused << mTelemetry->ClearOrigins();
 
   const nsLiteralCString doubleclick("doubleclick.net");
+  const nsLiteralCString unknown("this origin isn't known to Origin Telemetry");
   const nsLiteralCString telemetryTest1("telemetry.test_test1");
 
   Telemetry::RecordOrigin(OriginMetricID::TelemetryTest_Test1, doubleclick);
+  Telemetry::RecordOrigin(OriginMetricID::TelemetryTest_Test1, unknown);
 
   // Properly prepare the prio prefs
   // (Sourced from PrioEncoder.cpp from when it was being prototyped)
   const nsLiteralCString prioKeyA(
       "35AC1C7576C7C6EDD7FED6BCFC337B34D48CB4EE45C86BEEFB40BD8875707733");
   const nsLiteralCString prioKeyB(
       "26E6674E65425B823F1F1D5F96E3BB3EF9E406EC7FBA7DEF8B08A35DD135AF50");
   Preferences::SetCString("prio.publicKeyA", prioKeyA);