- Notifications
You must be signed in to change notification settings - Fork4.9k
Commit51f2359
committed
Fix potential infinite loop in regular expression execution.
In cfindloop(), if the initial call to shortest() reports that azero-length match is possible at the current search start point, but thenit is unable to construct any actual match to that, it'll just loop aroundwith the same start point, and thus make no progress. We need to force thestart point to be advanced. This is safe because the loop over "begin"points has already tried and failed to match starting at "close", so thereis surely no need to try that again.This bug was introduced in commite2bd904,wherein we allowed continued searching after we'd run out of matchpossibilities, but evidently failed to think hard enough about exactlywhere we needed to search next.Because of the way this code works, such a match failure is only possiblein the presence of backrefs --- otherwise, shortest()'s judgment that amatch is possible should always be correct. That probably explains howcome the bug has escaped detection for several years.The actual fix is a one-liner, but I took the trouble to add/improve somecomments related to the loop logic.After fixing that, the submitted test case "()*\1" didn't loop anymore.But it reported failure, though it seems like it ought to match azero-length string; both Tcl and Perl think it does. That seems to be fromoverenthusiastic optimization on my part when I rewrote the iteration matchlogic in commit173e29a: we can't just"declare victory" for a zero-length match without bothering to set matchdata for capturing parens inside the iterator node.Per fuzz testing by Greg Stark. The first part of this is a bug in allsupported branches, and the second part is a bug since 9.2 where theiteration rewrite happened.1 parentbb704a7 commit51f2359
3 files changed
+68
-13
lines changedLines changed: 35 additions & 13 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
448 | 448 |
| |
449 | 449 |
| |
450 | 450 |
| |
| 451 | + | |
451 | 452 |
| |
452 | 453 |
| |
453 | 454 |
| |
| |||
456 | 457 |
| |
457 | 458 |
| |
458 | 459 |
| |
459 |
| - | |
| 460 | + | |
460 | 461 |
| |
461 | 462 |
| |
462 | 463 |
| |
| 464 | + | |
463 | 465 |
| |
464 | 466 |
| |
465 | 467 |
| |
| |||
468 | 470 |
| |
469 | 471 |
| |
470 | 472 |
| |
| 473 | + | |
471 | 474 |
| |
472 | 475 |
| |
473 | 476 |
| |
| |||
482 | 485 |
| |
483 | 486 |
| |
484 | 487 |
| |
485 |
| - | |
| 488 | + | |
486 | 489 |
| |
| 490 | + | |
487 | 491 |
| |
488 | 492 |
| |
489 | 493 |
| |
| |||
502 | 506 |
| |
503 | 507 |
| |
504 | 508 |
| |
505 |
| - | |
| 509 | + | |
506 | 510 |
| |
507 | 511 |
| |
508 | 512 |
| |
509 |
| - | |
| 513 | + | |
510 | 514 |
| |
511 | 515 |
| |
512 | 516 |
| |
513 | 517 |
| |
514 | 518 |
| |
515 |
| - | |
| 519 | + | |
516 | 520 |
| |
517 | 521 |
| |
518 | 522 |
| |
519 | 523 |
| |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
520 | 531 |
| |
521 | 532 |
| |
522 | 533 |
| |
| |||
963 | 974 |
| |
964 | 975 |
| |
965 | 976 |
| |
966 |
| - | |
967 |
| - | |
968 |
| - | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
969 | 984 |
| |
970 | 985 |
| |
971 | 986 |
| |
972 |
| - | |
973 |
| - | |
974 |
| - | |
975 | 987 |
| |
976 |
| - | |
977 | 988 |
| |
978 | 989 |
| |
979 | 990 |
| |
| |||
1123 | 1134 |
| |
1124 | 1135 |
| |
1125 | 1136 |
| |
1126 |
| - | |
1127 | 1137 |
| |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
1128 | 1150 |
| |
1129 | 1151 |
| |
1130 | 1152 |
| |
|
Lines changed: 26 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
196 | 196 |
| |
197 | 197 |
| |
198 | 198 |
| |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + |
Lines changed: 7 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
50 | 50 |
| |
51 | 51 |
| |
52 | 52 |
| |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + |
0 commit comments
Comments
(0)