1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-10-06 09:37:12 +02:00

Prevent evaluating the SNFE until fully loaded

Related issue:
https://github.com/uBlockOrigin/uBlock-issues/issues/2925
This commit is contained in:
Raymond Hill 2023-11-03 10:01:40 -04:00
parent 605ad238b4
commit 89b272775a
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -4123,6 +4123,8 @@ FilterContainer.prototype.reset = function() {
this.optimizeTaskId = undefined; this.optimizeTaskId = undefined;
} }
this.notReady = false;
// Runtime registers // Runtime registers
this.$catBits = 0; this.$catBits = 0;
this.$tokenHash = 0; this.$tokenHash = 0;
@ -4215,6 +4217,8 @@ FilterContainer.prototype.freeze = function() {
this.goodFilters.clear(); this.goodFilters.clear();
filterArgsToUnit.clear(); filterArgsToUnit.clear();
this.notReady = false;
// Optimizing is not critical for the static network filtering engine to // Optimizing is not critical for the static network filtering engine to
// work properly, so defer this until later to allow for reduced delay to // work properly, so defer this until later to allow for reduced delay to
// readiness when no valid selfie is available. // readiness when no valid selfie is available.
@ -4723,6 +4727,8 @@ FilterContainer.prototype.fromSelfie = async function(storage, path) {
this.reset(); this.reset();
this.notReady = true;
const results = await Promise.all([ const results = await Promise.all([
storage.get(`${path}/main`), storage.get(`${path}/main`),
storage.get(`${path}/destHNTrieContainer`).then(details => storage.get(`${path}/destHNTrieContainer`).then(details =>
@ -4767,6 +4773,14 @@ FilterContainer.prototype.fromSelfie = async function(storage, path) {
this.bitsToBucketIndices = selfie.bitsToBucketIndices; this.bitsToBucketIndices = selfie.bitsToBucketIndices;
bucketsFromSelfie(selfie.buckets); bucketsFromSelfie(selfie.buckets);
urlTokenizer.fromSelfie(selfie.urlTokenizer); urlTokenizer.fromSelfie(selfie.urlTokenizer);
// If this point is never reached, it means the internal state is
// unreliable, and the caller is then responsible for resetting the
// engine and populate properly, in which case the `notReady` barrier
// will be properly reset.
this.notReady = false;
return true; return true;
}; };
@ -4811,6 +4825,8 @@ FilterContainer.prototype.matchAndFetchModifiers = function(
fctxt, fctxt,
modifierName modifierName
) { ) {
if ( this.notReady ) { return; }
const typeBits = typeNameToTypeValue[fctxt.type] || otherTypeBitValue; const typeBits = typeNameToTypeValue[fctxt.type] || otherTypeBitValue;
$requestURL = urlTokenizer.setURL(fctxt.url); $requestURL = urlTokenizer.setURL(fctxt.url);
@ -4988,6 +5004,8 @@ FilterContainer.prototype.realmMatchString = function(
typeBits, typeBits,
partyBits partyBits
) { ) {
if ( this.notReady ) { return false; }
const exactType = typeBits & 0x80000000; const exactType = typeBits & 0x80000000;
typeBits &= 0x7FFFFFFF; typeBits &= 0x7FFFFFFF;