mirror of
https://github.com/gorhill/uBlock.git
synced 2026-03-11 09:04:36 +00:00
Fix potential infinite loop when scanning for $ anchor
Related issue: https://github.com/uBlockOrigin/uBlock-issues/issues/3799 An infinite loop in the network filter parser was triggered when the following conditions were fulfilled: - There was a network option `$` anchor - There were only whitespace character(s) preceding the anchor - There was an invalid filter option following the anchor
This commit is contained in:
parent
e1028c299f
commit
02e5248d57
1 changed files with 4 additions and 4 deletions
|
|
@ -1200,7 +1200,7 @@ export class AstFilterParser {
|
|||
prev = this.linkRight(prev, next);
|
||||
patternBeg += 2;
|
||||
}
|
||||
let anchorBeg = this.indexOfNetAnchor(parentStr, patternBeg);
|
||||
let anchorBeg = this.indexOfNetAnchor(parentStr);
|
||||
if ( anchorBeg === -1 ) { return 0; }
|
||||
anchorBeg += parentBeg;
|
||||
if ( anchorBeg !== parentEnd ) {
|
||||
|
|
@ -1508,9 +1508,9 @@ export class AstFilterParser {
|
|||
}
|
||||
}
|
||||
|
||||
indexOfNetAnchor(s, start = 0) {
|
||||
indexOfNetAnchor(s) {
|
||||
const end = s.length;
|
||||
if ( end === start ) { return end; }
|
||||
if ( end === 0 ) { return end; }
|
||||
let j = s.lastIndexOf('$');
|
||||
if ( j === -1 ) { return end; }
|
||||
if ( (j+1) === end ) { return end; }
|
||||
|
|
@ -1518,7 +1518,7 @@ export class AstFilterParser {
|
|||
const before = s.charAt(j-1);
|
||||
if ( before === '$' ) { return -1; }
|
||||
if ( this.reNetOptionTokens.test(s.slice(j+1)) ) { return j; }
|
||||
if ( j === start ) { break; }
|
||||
if ( j === 0 ) { break; }
|
||||
j = s.lastIndexOf('$', j-1);
|
||||
if ( j === -1 ) { break; }
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue