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

syntax: fix overflow for big counted repetitions #996

Merged
merged 1 commit into from May 22, 2023

Conversation

BurntSushi
Copy link
Member

This fixes a bug where the calculation for the min/max length of a regex could overflow if the counted repetitions in the pattern are big enough. The panic only happens when debug assertions are enabled, which means there is no panic by default in release mode.

One may wonder whether other bad things happen in release mode though, since in that case, the arithmetic will wrap around instead. Since this is in new code and since the regex crate doesn't yet utilize the min/max attributes of an Hir, the wrap around in this case is completely innocuous.

Fixes #995

@finnbear
Copy link

That was fast 🦀 💯

Thank you for the crate, this patch, and your ongoing effort to clarify the security policy! 👌

This fixes a bug where the calculation for the min/max length of a regex
could overflow if the counted repetitions in the pattern are big enough.
The panic only happens when debug assertions are enabled, which means
there is no panic by default in release mode.

One may wonder whether other bad things happen in release mode though,
since in that case, the arithmetic will wrap around instead. Since this
is in new code and since the regex crate doesn't yet utilize the min/max
attributes of an Hir, the wrap around in this case is completely
innocuous.

Fixes #995
@BurntSushi
Copy link
Member Author

No problem! I actually had this fixed in a branch before it was reported, but I just didn't make the connection that it was impacting the regex release. (Because the bug is in new code that isn't used but is actually executed.) So I just had to split this patch out. :-)

@BurntSushi BurntSushi merged commit f9aec41 into master May 22, 2023
10 checks passed
@BurntSushi BurntSushi deleted the ag/fix-debug-panic branch May 22, 2023 21:51
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.

integer overflow on a particular regex
2 participants