File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -37,10 +37,9 @@ Brower build:
37
37
- [ Issue] ( https://github.com/highlightjs/highlight.js/issues/2505 ) (bug) Fix: Version 10 fails to load as CommonJS module. (#2511 ) [ Josh Goebel] [ ]
38
38
- [ Issue] ( https://github.com/highlightjs/highlight.js/issues/2505 ) (removal) AMD module loading support has been removed. (#2511 ) [ Josh Goebel] [ ]
39
39
40
-
41
40
Parser Engine Changes:
42
41
43
- - ...
42
+ - [ Issue ] ( https://github.com/highlightjs/highlight.js/issues/2522 ) fix(parser) Fix freez issue with illegal 0 width matches ( # 2524 ) [ Josh Goebel ] [ ]
44
43
45
44
46
45
[ Josh Goebel ] : https://github.com/yyyc514
Original file line number Diff line number Diff line change @@ -365,6 +365,23 @@ const HLJS = function(hljs) {
365
365
}
366
366
}
367
367
368
+ // edge case for when illegal matches $ (end of line) which is technically
369
+ // a 0 width match but not a begin/end match so it's not caught by the
370
+ // first handler (when ignoreIllegals is true)
371
+ if ( match . type === "illegal" && lexeme === "" ) {
372
+ // advance so we aren't stuck in an infinite loop
373
+ return 1 ;
374
+ }
375
+
376
+ // infinite loops are BAD, this is a last ditch catch all. if we have a
377
+ // decent number of iterations yet our index (cursor position in our
378
+ // parsing) still 3x behind our index then something is very wrong
379
+ // so we bail
380
+ if ( iterations > 100000 && iterations > match . index * 3 ) {
381
+ const err = new Error ( 'potential infinite loop, way more iterations than matches' ) ;
382
+ throw err ;
383
+ }
384
+
368
385
/*
369
386
Why might be find ourselves here? Only one occasion now. An end match that was
370
387
triggered but could not be completed. When might this happen? When an `endSameasBegin`
@@ -396,12 +413,14 @@ const HLJS = function(hljs) {
396
413
var mode_buffer = '' ;
397
414
var relevance = 0 ;
398
415
var index = 0 ;
416
+ var iterations = 0 ;
399
417
var continueScanAtSamePosition = false ;
400
418
401
419
try {
402
420
top . matcher . considerAll ( ) ;
403
421
404
422
for ( ; ; ) {
423
+ iterations ++ ;
405
424
if ( continueScanAtSamePosition ) {
406
425
continueScanAtSamePosition = false ;
407
426
// only regexes not matched previously will now be
You can’t perform that action at this time.
0 commit comments