Commit 6b13124
committed
fix(security): correct three defects in the lookaround split decomposition
A fourth reviewer, given no context beyond "these scanners are new and
unreviewed", differential-tested them against the built-in engine over ~62k
comparisons and found three real defects in code added an hour earlier. All
were reachable through RegexChunker with plausible patterns, and all silently
produced different chunks rather than failing.
1. **Top-level alternation was reshaped into a different pattern.**
`(?<=\.)\s+|\n\n` means `((?<=\.)\s+)|(\n\n)`, but decomposing it produced
`(?:\.)(\s+|\n\n)` — demanding the period before *both* branches. It could
lose boundaries (`"Heading\n\nAlpha beta.\nGamma delta."` split in 2, not 3)
and invent them. No grouping recovers the original meaning, so patterns whose
middle alternates at the top level are now declined outright, which also
removes an asymmetry: `\n\n|(?<=\.)\s` already threw.
2. **A capturing group inside the lookbehind stole group 1.** `(?<=(a))b` cut at
the assertion instead of the delimiter, and where the group did not
participate `start(1)` was -1, so `find` and `test` contradicted each other.
The middle is now captured by name, immune to numbering.
3. **Consuming the assertion text swallowed every other boundary.** The compiled
form matched `behind + middle + ahead`, so any boundary whose lookahead
doubles as the next one's lookbehind was skipped: `(?<=\w)\s+(?=[A-Z])` over
`"A B C D"` split 2 of 3 gaps. Each iteration now resumes at the end of the
delimiter rather than the end of the match. This was documented as affecting
only self-overlapping delimiters; that was wrong and far too narrow.
The reviewer confirmed `translateToRe2` and `closingParen` clean across
exhaustive escape-state, character-class, and paren-matching probes, and that
nothing added is superlinear.
One divergence remains and is now documented rather than overstated: when
delimiters themselves overlap (a single-character middle whose matches abut, as
in `(?<=\w).(?=\w)`), a match starting behind the cursor is dropped instead of
emitting the empty segment the built-in engine produces. Splitters that consume
whitespace or punctuation between tokens do not overlap and match exactly.1 parent 6651434 commit 6b13124
2 files changed
Lines changed: 95 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
171 | 200 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
153 | 183 | | |
154 | 184 | | |
155 | 185 | | |
| |||
195 | 225 | | |
196 | 226 | | |
197 | 227 | | |
| 228 | + | |
198 | 229 | | |
199 | 230 | | |
200 | 231 | | |
| |||
208 | 239 | | |
209 | 240 | | |
210 | 241 | | |
211 | | - | |
212 | | - | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
213 | 252 | | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
218 | 258 | | |
219 | 259 | | |
220 | 260 | | |
| |||
225 | 265 | | |
226 | 266 | | |
227 | 267 | | |
228 | | - | |
| 268 | + | |
229 | 269 | | |
230 | 270 | | |
231 | 271 | | |
| |||
234 | 274 | | |
235 | 275 | | |
236 | 276 | | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
237 | 284 | | |
238 | 285 | | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
| 286 | + | |
243 | 287 | | |
244 | 288 | | |
245 | | - | |
246 | 289 | | |
247 | | - | |
248 | | - | |
249 | | - | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
250 | 296 | | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
255 | 302 | | |
256 | 303 | | |
257 | 304 | | |
| |||
0 commit comments