Backed out 3 changesets (bug 1777600) for causing safebrowsing crashes. a=backout
Backed out changeset be9e99eac13c (bug 1777600) Backed out changeset ccaf8757d382 (bug 1777600) Backed out changeset c0624a8aa7c2 (bug 1777600)
This commit is contained in:
@@ -1610,14 +1610,28 @@ nsresult Classifier::ReadNoiseEntries(const Prefix& aPrefix,
|
||||
const nsACString& aTableName,
|
||||
uint32_t aCount,
|
||||
PrefixArray& aNoiseEntries) {
|
||||
FallibleTArray<uint32_t> prefixes;
|
||||
nsresult rv;
|
||||
|
||||
RefPtr<LookupCache> cache = GetLookupCache(aTableName);
|
||||
if (!cache) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
RefPtr<LookupCacheV2> cacheV2 = LookupCache::Cast<LookupCacheV2>(cache);
|
||||
RefPtr<LookupCacheV4> cacheV4 = LookupCache::Cast<LookupCacheV4>(cache);
|
||||
MOZ_ASSERT_IF(cacheV2, !cacheV4);
|
||||
if (cacheV2) {
|
||||
rv = cacheV2->GetPrefixes(prefixes);
|
||||
} else {
|
||||
rv = LookupCache::Cast<LookupCacheV4>(cache)->GetFixedLengthPrefixes(
|
||||
prefixes);
|
||||
}
|
||||
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (prefixes.Length() == 0) {
|
||||
NS_WARNING("Could not find prefix in PrefixSet during noise lookup");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// We do not want to simply pick random prefixes, because this would allow
|
||||
// averaging out the noise by analysing the traffic from Firefox users.
|
||||
@@ -1630,36 +1644,20 @@ nsresult Classifier::ReadNoiseEntries(const Prefix& aPrefix,
|
||||
// for.
|
||||
// http://en.wikipedia.org/wiki/Linear_congruential_generator
|
||||
|
||||
uint32_t m = cache->PrefixLength();
|
||||
uint32_t m = prefixes.Length();
|
||||
uint32_t a = aCount % m;
|
||||
uint32_t idx = aPrefix.ToUint32() % m;
|
||||
|
||||
for (size_t i = 0; i < aCount; i++) {
|
||||
idx = (a * idx + a) % m;
|
||||
|
||||
uint32_t hash;
|
||||
|
||||
nsresult rv;
|
||||
if (cacheV2) {
|
||||
rv = cacheV2->GetPrefixByIndex(idx, &hash);
|
||||
} else {
|
||||
// We don't add noises for variable length prefix because of simplicity,
|
||||
// so we will only get fixed length prefix (4 bytes).
|
||||
rv = cacheV4->GetFixedLengthPrefixByIndex(idx, &hash);
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING(
|
||||
"Could not find the target prefix in PrefixSet during noise lookup");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
Prefix newPrefix;
|
||||
uint32_t hash = prefixes[idx];
|
||||
// In the case V4 little endian, we did swapping endian when converting from
|
||||
// char* to int, should revert endian to make sure we will send hex string
|
||||
// correctly See https://bugzilla.mozilla.org/show_bug.cgi?id=1283007#c23
|
||||
if (!cacheV2 && !bool(MOZ_BIG_ENDIAN())) {
|
||||
hash = NativeEndian::swapFromBigEndian(hash);
|
||||
hash = NativeEndian::swapFromBigEndian(prefixes[idx]);
|
||||
}
|
||||
|
||||
newPrefix.FromUint32(hash);
|
||||
|
||||
@@ -923,13 +923,6 @@ nsresult LookupCacheV2::GetPrefixes(FallibleTArray<uint32_t>& aAddPrefixes,
|
||||
return mVLPrefixSet->GetFixedLengthPrefixes(&aAddPrefixes, &aAddCompletes);
|
||||
}
|
||||
|
||||
nsresult LookupCacheV2::GetPrefixByIndex(uint32_t aIndex,
|
||||
uint32_t* aOutPrefix) const {
|
||||
NS_ENSURE_ARG_POINTER(aOutPrefix);
|
||||
|
||||
return mVLPrefixSet->GetFixedLengthPrefixByIndex(aIndex, aOutPrefix);
|
||||
}
|
||||
|
||||
void LookupCacheV2::AddGethashResultToCache(
|
||||
const AddCompleteArray& aAddCompletes, const MissPrefixArray& aMissPrefixes,
|
||||
int64_t aExpirySec) {
|
||||
|
||||
@@ -214,8 +214,6 @@ class LookupCache {
|
||||
// Currently this is only used by testcase.
|
||||
bool IsInCache(uint32_t key) const { return mFullHashCache.Get(key); };
|
||||
|
||||
uint32_t PrefixLength() const { return mVLPrefixSet->Length(); }
|
||||
|
||||
#if DEBUG
|
||||
void DumpCache() const;
|
||||
#endif
|
||||
@@ -314,7 +312,6 @@ class LookupCacheV2 final : public LookupCache {
|
||||
nsresult GetPrefixes(FallibleTArray<uint32_t>& aAddPrefixes);
|
||||
nsresult GetPrefixes(FallibleTArray<uint32_t>& aAddPrefixes,
|
||||
FallibleTArray<nsCString>& aAddCompletes);
|
||||
nsresult GetPrefixByIndex(uint32_t aIndex, uint32_t* aOutPrefix) const;
|
||||
|
||||
// This will Clear() the passed arrays when done.
|
||||
// 'aExpirySec' is used by testcase to config an expired time.
|
||||
|
||||
@@ -155,13 +155,6 @@ nsresult LookupCacheV4::GetFixedLengthPrefixes(
|
||||
return mVLPrefixSet->GetFixedLengthPrefixes(&aPrefixes, nullptr);
|
||||
}
|
||||
|
||||
nsresult LookupCacheV4::GetFixedLengthPrefixByIndex(
|
||||
uint32_t aIndex, uint32_t* aOutPrefix) const {
|
||||
NS_ENSURE_ARG_POINTER(aOutPrefix);
|
||||
|
||||
return mVLPrefixSet->GetFixedLengthPrefixByIndex(aIndex, aOutPrefix);
|
||||
}
|
||||
|
||||
nsresult LookupCacheV4::ClearLegacyFile() {
|
||||
nsCOMPtr<nsIFile> file;
|
||||
nsresult rv = mStoreDirectory->Clone(getter_AddRefs(file));
|
||||
|
||||
@@ -28,8 +28,6 @@ class LookupCacheV4 final : public LookupCache {
|
||||
|
||||
nsresult GetPrefixes(PrefixStringMap& aPrefixMap);
|
||||
nsresult GetFixedLengthPrefixes(FallibleTArray<uint32_t>& aPrefixes);
|
||||
nsresult GetFixedLengthPrefixByIndex(uint32_t aIndex,
|
||||
uint32_t* aOutPrefix) const;
|
||||
|
||||
// ApplyUpdate will merge data stored in aTableUpdate with prefixes in
|
||||
// aInputMap.
|
||||
|
||||
@@ -247,13 +247,6 @@ nsresult VariableLengthPrefixSet::GetFixedLengthPrefixes(
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult VariableLengthPrefixSet::GetFixedLengthPrefixByIndex(
|
||||
uint32_t aIndex, uint32_t* aOutPrefix) const {
|
||||
NS_ENSURE_ARG_POINTER(aOutPrefix);
|
||||
|
||||
return mFixedPrefixSet->GetPrefixByIndex(aIndex, aOutPrefix);
|
||||
}
|
||||
|
||||
// It should never be the case that more than one hash prefixes match a given
|
||||
// full hash. However, if that happens, this method returns any one of them.
|
||||
// It does not guarantee which one of those will be returned.
|
||||
@@ -388,10 +381,6 @@ uint32_t VariableLengthPrefixSet::CalculatePreallocateSize() const {
|
||||
return fileSize;
|
||||
}
|
||||
|
||||
uint32_t VariableLengthPrefixSet::Length() const {
|
||||
return mFixedPrefixSet->Length();
|
||||
}
|
||||
|
||||
nsresult VariableLengthPrefixSet::WritePrefixes(
|
||||
nsCOMPtr<nsIOutputStream>& out) const {
|
||||
MutexAutoLock lock(mLock);
|
||||
|
||||
@@ -30,8 +30,6 @@ class VariableLengthPrefixSet final : public nsIMemoryReporter {
|
||||
nsresult GetPrefixes(mozilla::safebrowsing::PrefixStringMap& aPrefixMap);
|
||||
nsresult GetFixedLengthPrefixes(FallibleTArray<uint32_t>* aPrefixes,
|
||||
FallibleTArray<nsCString>* aCompletes);
|
||||
nsresult GetFixedLengthPrefixByIndex(uint32_t aIndex,
|
||||
uint32_t* aOutPrefix) const;
|
||||
nsresult Matches(uint32_t aPrefix, const nsACString& aFullHash,
|
||||
uint32_t* aLength) const;
|
||||
nsresult IsEmpty(bool* aEmpty) const;
|
||||
@@ -39,7 +37,6 @@ class VariableLengthPrefixSet final : public nsIMemoryReporter {
|
||||
nsresult WritePrefixes(nsCOMPtr<nsIOutputStream>& out) const;
|
||||
nsresult LoadPrefixes(nsCOMPtr<nsIInputStream>& in);
|
||||
uint32_t CalculatePreallocateSize() const;
|
||||
uint32_t Length() const;
|
||||
|
||||
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
|
||||
|
||||
|
||||
@@ -176,10 +176,10 @@ nsresult nsUrlClassifierPrefixSet::MakePrefixSet(const uint32_t* aPrefixes,
|
||||
}
|
||||
|
||||
nsresult nsUrlClassifierPrefixSet::GetPrefixesNative(
|
||||
FallibleTArray<uint32_t>& aOutArray) {
|
||||
FallibleTArray<uint32_t>& outArray) {
|
||||
MutexAutoLock lock(mLock);
|
||||
|
||||
if (!aOutArray.SetLength(mTotalPrefixes, fallible)) {
|
||||
if (!outArray.SetLength(mTotalPrefixes, fallible)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ nsresult nsUrlClassifierPrefixSet::GetPrefixesNative(
|
||||
if (prefixCnt >= mTotalPrefixes) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
aOutArray[prefixCnt++] = prefix;
|
||||
outArray[prefixCnt++] = prefix;
|
||||
|
||||
if (mIndexDeltas.IsEmpty()) {
|
||||
continue;
|
||||
@@ -203,7 +203,7 @@ nsresult nsUrlClassifierPrefixSet::GetPrefixesNative(
|
||||
if (prefixCnt >= mTotalPrefixes) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
aOutArray[prefixCnt++] = prefix;
|
||||
outArray[prefixCnt++] = prefix;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,42 +211,6 @@ nsresult nsUrlClassifierPrefixSet::GetPrefixesNative(
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsUrlClassifierPrefixSet::GetPrefixByIndex(
|
||||
uint32_t aIndex, uint32_t* aOutPrefix) const {
|
||||
NS_ENSURE_ARG_POINTER(aOutPrefix);
|
||||
|
||||
MutexAutoLock lock(mLock);
|
||||
MOZ_ASSERT(aIndex < mTotalPrefixes);
|
||||
|
||||
// We can directly get the target index if the delta algorithm didn't apply.
|
||||
if (mIndexDeltas.IsEmpty()) {
|
||||
*aOutPrefix = mIndexPrefixes[aIndex];
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// The prefix set was compressed by the delta algorithm, we have to iterate
|
||||
// the delta index to find out the right bucket.
|
||||
for (uint32_t i = 0; i < mIndexDeltas.Length(); i++) {
|
||||
// The target index is in the current delta bucket.
|
||||
if (aIndex <= mIndexDeltas[i].Length()) {
|
||||
MOZ_ASSERT(aIndex <= DELTAS_LIMIT);
|
||||
|
||||
uint32_t prefix = mIndexPrefixes[i];
|
||||
|
||||
for (uint32_t j = 0; j < aIndex; j++) {
|
||||
prefix += mIndexDeltas[i][j];
|
||||
}
|
||||
|
||||
*aOutPrefix = prefix;
|
||||
break;
|
||||
}
|
||||
|
||||
aIndex -= mIndexDeltas[i].Length() + 1;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUrlClassifierPrefixSet::GetPrefixes(uint32_t* aCount, uint32_t** aPrefixes) {
|
||||
// No need to get mLock here because this function does not directly touch
|
||||
@@ -497,12 +461,6 @@ uint32_t nsUrlClassifierPrefixSet::CalculatePreallocateSize() const {
|
||||
return fileSize;
|
||||
}
|
||||
|
||||
uint32_t nsUrlClassifierPrefixSet::Length() const {
|
||||
MutexAutoLock lock(mLock);
|
||||
|
||||
return mTotalPrefixes;
|
||||
}
|
||||
|
||||
nsresult nsUrlClassifierPrefixSet::WritePrefixes(
|
||||
nsCOMPtr<nsIOutputStream>& out) const {
|
||||
MutexAutoLock lock(mLock);
|
||||
|
||||
@@ -37,12 +37,10 @@ class nsUrlClassifierPrefixSet final : public nsIUrlClassifierPrefixSet {
|
||||
NS_IMETHOD Contains(uint32_t aPrefix, bool* aFound) override;
|
||||
NS_IMETHOD IsEmpty(bool* aEmpty) override;
|
||||
|
||||
nsresult GetPrefixesNative(FallibleTArray<uint32_t>& aOutArray);
|
||||
nsresult GetPrefixByIndex(uint32_t aIndex, uint32_t* aOutPrefix) const;
|
||||
nsresult GetPrefixesNative(FallibleTArray<uint32_t>& outArray);
|
||||
nsresult WritePrefixes(nsCOMPtr<nsIOutputStream>& out) const;
|
||||
nsresult LoadPrefixes(nsCOMPtr<nsIInputStream>& in);
|
||||
uint32_t CalculatePreallocateSize() const;
|
||||
uint32_t Length() const;
|
||||
|
||||
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
|
||||
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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 "mozilla/Preferences.h"
|
||||
#include "nsString.h"
|
||||
#include "nsUrlClassifierPrefixSet.h"
|
||||
|
||||
#include "Common.h"
|
||||
|
||||
// This function generate N 4 byte prefixes.
|
||||
static void RandomPrefixes(uint32_t N, nsTArray<uint32_t>& array) {
|
||||
array.Clear();
|
||||
array.SetCapacity(N);
|
||||
|
||||
for (uint32_t i = 0; i < N; i++) {
|
||||
bool added = false;
|
||||
|
||||
while (!added) {
|
||||
nsAutoCString prefix;
|
||||
char* dst = prefix.BeginWriting();
|
||||
for (uint32_t j = 0; j < 4; j++) {
|
||||
dst[j] = static_cast<char>(rand() % 256);
|
||||
}
|
||||
|
||||
const char* src = prefix.BeginReading();
|
||||
uint32_t data = 0;
|
||||
memcpy(&data, src, sizeof(data));
|
||||
|
||||
if (!array.Contains(data)) {
|
||||
array.AppendElement(data);
|
||||
added = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Comparator {
|
||||
bool LessThan(const uint32_t& aA, const uint32_t& aB) const {
|
||||
return aA < aB;
|
||||
}
|
||||
|
||||
bool Equals(const uint32_t& aA, const uint32_t& aB) const {
|
||||
return aA == aB;
|
||||
}
|
||||
};
|
||||
|
||||
array.Sort(Comparator());
|
||||
}
|
||||
|
||||
void RunTest(uint32_t aTestSize) {
|
||||
RefPtr<nsUrlClassifierPrefixSet> prefixSet = new nsUrlClassifierPrefixSet();
|
||||
nsTArray<uint32_t> array;
|
||||
|
||||
RandomPrefixes(aTestSize, array);
|
||||
|
||||
nsresult rv = prefixSet->SetPrefixes(array.Elements(), array.Length());
|
||||
ASSERT_NS_SUCCEEDED(rv);
|
||||
|
||||
for (uint32_t i = 0; i < array.Length(); i++) {
|
||||
uint32_t value = 0;
|
||||
rv = prefixSet->GetPrefixByIndex(i, &value);
|
||||
ASSERT_NS_SUCCEEDED(rv);
|
||||
|
||||
ASSERT_TRUE(value == array[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(URLClassifierPrefixSet, GetTargetPrefixWithLargeSet)
|
||||
{
|
||||
// Make sure the delta algorithm will be used.
|
||||
static const char prefKey[] = "browser.safebrowsing.prefixset_max_array_size";
|
||||
mozilla::Preferences::SetUint(prefKey, 10000);
|
||||
|
||||
// Ideally, we should test more than 512 * 1024 entries. But, it will make the
|
||||
// test too long. So, we test 100k entries instead.
|
||||
RunTest(100000);
|
||||
}
|
||||
|
||||
TEST(URLClassifierPrefixSet, GetTargetPrefixWithSmallSet)
|
||||
{
|
||||
// Make sure the delta algorithm won't be used.
|
||||
static const char prefKey[] = "browser.safebrowsing.prefixset_max_array_size";
|
||||
mozilla::Preferences::SetUint(prefKey, 10000);
|
||||
|
||||
RunTest(1000);
|
||||
}
|
||||
@@ -20,7 +20,6 @@ UNIFIED_SOURCES += [
|
||||
"TestFindFullHash.cpp",
|
||||
"TestLookupCacheV4.cpp",
|
||||
"TestPerProviderDirectory.cpp",
|
||||
"TestPrefixSet.cpp",
|
||||
"TestProtocolParser.cpp",
|
||||
"TestRiceDeltaDecoder.cpp",
|
||||
"TestSafebrowsingHash.cpp",
|
||||
|
||||
Reference in New Issue
Block a user