-
Notifications
You must be signed in to change notification settings - Fork 462
Move has_visited check to the top of the loop in backtrack::Bounded::step #384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Whoops, was only running a subset of the tests. Fix on the way... |
Sorry that I haven't had a chance to look at this yet, but I'm skeptical of the approach in this PR. The code that re-implements matching semantics in an ad hoc fashion on the AST seems particularly unfortunate. I haven't given any thought to this, but both RE2 and Go's regexp library have a bitstate backtracker like the one in this crate. Are those regex engines susceptible to this problem? If not, how do they solve it? |
In particular, I'd like to understand why the |
…step This prevents us from executing instructions if they have been executed before, rather than returning after the instruction has already been executed. Fixes rust-lang#375
|
Does this new change look better? It's certainly smaller in scope and size. |
@adamcrume Yes, much nicer! Thank you for doing this work to fix this subtle bug. It is most appreciated! @bors r+ |
📌 Commit 6356d1a has been approved by |
Move has_visited check to the top of the loop in backtrack::Bounded::step …pressions With certain repeated empty expressions similar to (x*)*?, the backtracker can go into an infinite loop. This change adds the Progress instruction which requires the engine to make progress to continue matching a repeated subexpression. Fixes #375 Note that this was inspired by https://swtch.com/~rsc/regexp/regexp2.html#real (mentioned in HACKING.md), which mentions that a progress instruction can be used to prevent backtracking loops.
☀️ Test successful - status-appveyor, status-travis |
…pressions
With certain repeated empty expressions similar to (x*)*?, the backtracker can
go into an infinite loop. This change adds the Progress instruction which
requires the engine to make progress to continue matching a repeated
subexpression.
Fixes #375
Note that this was inspired by https://swtch.com/~rsc/regexp/regexp2.html#real (mentioned in HACKING.md), which mentions that a progress instruction can be used to prevent backtracking loops.