Skip to content

Commit

Permalink
Use a better value to mark end of sequence of tokens
Browse files Browse the repository at this point in the history
Related issue:
- uBlockOrigin/uBlock-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.
  • Loading branch information
gorhill committed Mar 11, 2022
1 parent 858fdac commit bc4f392
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/js/static-net-filtering.js
Expand Up @@ -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;

/******************************************************************************/

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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) &&
Expand Down

0 comments on commit bc4f392

Please sign in to comment.