From bc4f392a475dac18b82111919ad38ee93beee42e Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Fri, 11 Mar 2022 17:22:12 -0500 Subject: [PATCH] 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. --- src/js/static-net-filtering.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/js/static-net-filtering.js b/src/js/static-net-filtering.js index 53ef8a48b90b9..ce5291021db42 100644 --- a/src/js/static-net-filtering.js +++ b/src/js/static-net-filtering.js @@ -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) &&