Use a better value to mark end of sequence of tokens

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/2041

The value 0xFFFFFFFF will be used instead of 0 to mark the end of
a sequence of tokens, as the value 0xFFFFFFFF can't happen as a
result of computing a token hash, since the four most significant
bits are always 0 in a computed token hash.
This commit is contained in:
Raymond Hill 2022-03-11 17:22:12 -05:00
parent 858fdaced3
commit bc4f392a47
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 4 additions and 3 deletions

View File

@ -176,6 +176,7 @@ const ANY_TOKEN_HASH = 0x20000000;
const ANY_HTTPS_TOKEN_HASH = 0x30000000;
const ANY_HTTP_TOKEN_HASH = 0x40000000;
const EMPTY_TOKEN_HASH = 0xF0000000;
const INVALID_TOKEN_HASH = 0xFFFFFFFF;
/******************************************************************************/
@ -2581,7 +2582,7 @@ const urlTokenizer = new (class {
}
this._tokens[i+0] = NO_TOKEN_HASH;
this._tokens[i+1] = 0;
this._tokens[i+2] = 0;
this._tokens[i+2] = INVALID_TOKEN_HASH;
this._tokenized = true;
return this._tokens;
}
@ -3981,7 +3982,7 @@ FilterContainer.prototype.matchAndFetchModifiers = function(
let th = 0, iunit = 0;
for (;;) {
th = tokenHashes[i];
if ( th === 0 ) { break; }
if ( th === INVALID_TOKEN_HASH ) { break; }
env.th = th;
$tokenBeg = tokenHashes[i+1];
if (
@ -4173,7 +4174,7 @@ FilterContainer.prototype.realmMatchString = function(
let i = 0;
for (;;) {
tokenHash = tokenHashes[i];
if ( tokenHash === 0 ) { return false; }
if ( tokenHash === INVALID_TOKEN_HASH ) { return false; }
$tokenBeg = tokenHashes[i+1];
if (
(ibucket00 !== 0) &&