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
Prevent ReDoS in Spanish sentence splitting regex #1084
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Gallaecio
approved these changes
Jan 11, 2023
Closing and reopening to re-trigger CI jobs… |
In Spanish, questions start with an upside down question mark: > ¿Vos bueno? This was already handled in the original regex, but the original regex was vulnerable for regular expression denial of service (ReDoS). In the new regex, we either search for normal end-of-sentence optionally followed by a ¿ or ¡, or a ¿ or ¡ on its own. A change is that the normal end-of-sentence (.!?;…) has to come before the ¡ or ¿, but I think this is acceptable. This PR also adds some Spanish test cases. These hit the sentence splitting logic, but the exact result of the splitting is not tested. Fixes scrapinghub#869
Consume whitespace if there is any, but still match if there isn't. This makes most sense for \n followed immediately by ¿. This also means we don't have to backtrack if there isn't any whitespace after a line ending.
Sjord
force-pushed
the
fix-spanish-regexdos
branch
from
January 11, 2023 14:56
fe59143
to
ef78400
Compare
I rebased to master. |
The previous code wouldn't remove multiple empty strings in a row, due to modifying the list during the loop. We use `filter` with the default identity function instead.
serhii73
approved these changes
Jan 11, 2023
wRAR
approved these changes
Jan 11, 2023
We have a new release with this PR. Thank you @Sjord |
dotlambda
added a commit
to dotlambda/nixpkgs
that referenced
this pull request
Jan 24, 2023
13 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In Spanish, questions start with an upside down question mark:
This was already handled in the original regex, but the original regex was vulnerable for regular expression denial of service (ReDoS). In the new regex, we either search for normal end-of-sentence optionally followed by a ¿ or ¡, or a ¿ or ¡ on its own. A change is that the normal end-of-sentence (.!?;…) has to come before the ¡ or ¿, but I think this is acceptable.
This PR also adds some Spanish test cases. These hit the sentence splitting logic, but the exact result of the splitting is not tested.
Fixes #869