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

out of range for slice in next_regex #104

Closed
marryjianjian opened this issue Jul 16, 2024 · 4 comments · Fixed by #105
Closed

out of range for slice in next_regex #104

marryjianjian opened this issue Jul 16, 2024 · 4 comments · Fixed by #105

Comments

@marryjianjian
Copy link

String::from_utf8_lossy(&self.stream.buffer[self.current_start..self.stream.idx])

when input is /\ (just 2 char, slash and backslash), it can cause
range end index 3 out of range for slice of length 2
image

It seems that when found char \ it will call skip_bytes. And this function will not check idx just increase it

@marryjianjian
Copy link
Author

Maybe we could use skip instead of skip_bytes when found char \ or check the idx value before throw out that error.
I don't know which solution (or any other) is better.

@FreeMasen
Copy link
Collaborator

Thank you for the bug report, we for sure don't want to panic on invalid input. Sorry i haven't been faster to respond but I have been quite busy lately, I can take a look this weekend.

@FreeMasen
Copy link
Collaborator

Thank you again for the bug report. I was finally able to take a look this afternoon and found the issue. Assuming that a \ is always an escape sequence in a regex when the stream ends was the issue. I was able to correct this by adding a check that !self.stream.at_end() before skipping ahead.

I should have the 0.11 fix published today and I will need to update the 0.12 version to match

@marryjianjian
Copy link
Author

Thanks your fix

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 a pull request may close this issue.

2 participants