Skip to content

Commit 889c0eb

Browse files
committed
Fix potential infinite loop when scanning for $ anchor
Related issue: uBlockOrigin/uBlock-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
1 parent cb767f4 commit 889c0eb

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/js/static-filtering-parser.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ export class AstFilterParser {
12001200
prev = this.linkRight(prev, next);
12011201
patternBeg += 2;
12021202
}
1203-
let anchorBeg = this.indexOfNetAnchor(parentStr, patternBeg);
1203+
let anchorBeg = this.indexOfNetAnchor(parentStr);
12041204
if ( anchorBeg === -1 ) { return 0; }
12051205
anchorBeg += parentBeg;
12061206
if ( anchorBeg !== parentEnd ) {
@@ -1508,17 +1508,17 @@ export class AstFilterParser {
15081508
}
15091509
}
15101510

1511-
indexOfNetAnchor(s, start = 0) {
1511+
indexOfNetAnchor(s) {
15121512
const end = s.length;
1513-
if ( end === start ) { return end; }
1513+
if ( end === 0 ) { return end; }
15141514
let j = s.lastIndexOf('$');
15151515
if ( j === -1 ) { return end; }
15161516
if ( (j+1) === end ) { return end; }
15171517
for (;;) {
15181518
const before = s.charAt(j-1);
15191519
if ( before === '$' ) { return -1; }
15201520
if ( this.reNetOptionTokens.test(s.slice(j+1)) ) { return j; }
1521-
if ( j === start ) { break; }
1521+
if ( j === 0 ) { break; }
15221522
j = s.lastIndexOf('$', j-1);
15231523
if ( j === -1 ) { break; }
15241524
}

0 commit comments

Comments
 (0)