Commit dea87ba
Fix quadratic parsing of leading whitespace
`geckoRe` and `javaScriptCoreRe` began with `^\s*` followed immediately by
a group that also matches whitespace — `(.*?)` and `([^@]*)` respectively.
A leading run of spaces could therefore be divided between the two in n
ways, and a line that did not match forced the engine through every split:
n= 1000 4.2 ms
n= 2000 14.6 ms
n= 4000 57.9 ms
n= 8000 231.3 ms
n=16000 924.0 ms
`err.stack` embeds the message, so attacker-influenced text reaches this
directly: a 30k-space message took ~3.3s of blocked event loop.
The leading `\s*` is redundant, since the following group already matches
whitespace. Its only real effect was keeping leading whitespace out of the
captured methodName, so that is handled where the capture is read.
After: 8000 -> 0.16ms, 16000 -> 0.37ms, 32000 -> 0.63ms, ~2x per doubling.
`chromeRe`, `winjsRe` and `nodeRe` are untouched: each has a literal `at `
after `^\s*`, which anchors the boundary and prevents the ambiguity.
Co-authored-by: Claude Code <[email protected]>1 parent 68b3947 commit dea87ba
2 files changed
Lines changed: 28 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
| 74 | + | |
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
96 | | - | |
| 96 | + | |
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
103 | | - | |
| 103 | + | |
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
114 | | - | |
| 114 | + | |
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
6 | 30 | | |
7 | 31 | | |
8 | 32 | | |
| |||
0 commit comments