Skip to content
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

dfa: fix bug in how the reverse DFA is called #970

Merged
merged 1 commit into from Mar 25, 2023
Merged

Conversation

BurntSushi
Copy link
Member

In turns out that in some calls to Fsm::reverse, we were passing an incorrect start offset. Namely, the haystack we pass is sub-sliced at &text[start..], but in some places, we were passing text.len() as the start offset of the reverse search. But of course, it should be text.len() - start. This was indeed the case in most places, but it looks like it needed to be corrected in two additional places.

I've also added this test to regex-automata's set of regression tests and can confirm that it doesn't happen there. (regex-automata is far more principled about handling offsets like this.)

Fixes #969

In turns out that in *some* calls to Fsm::reverse, we were passing an
incorrect start offset. Namely, the haystack we pass is sub-sliced at
`&text[start..]`, but in some places, we were passing `text.len()` as
the start offset of the reverse search. But of course, it should be
`text.len() - start`. This was indeed the case in most places, but it
looks like it needed to be corrected in two additional places.

I've also added this test to regex-automata's set of regression tests
and can confirm that it doesn't happen there. (regex-automata is far
more principled about handling offsets like this.)

Fixes #969
@BurntSushi BurntSushi merged commit d94f955 into master Mar 25, 2023
10 checks passed
@BurntSushi BurntSushi deleted the ag/fix-i969 branch March 25, 2023 00:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Index out of bounds panic when using shortest_match_at, is_match_at with end-anchored regex
1 participant