Repository navigation
grep: report error instead of panicking on Oniguruma retry limit - #228
yunusarda-sudo wants to merge 1 commit into
Conversation
Merging this PR will not alter performance1 warning
Comparing Footnotes
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #228 +/- ##
==========================================
- Coverage 96.89% 96.80% -0.10%
==========================================
Files 6 6
Lines 2160 2191 +31
Branches 235 240 +5
==========================================
+ Hits 2093 2121 +28
- Misses 67 70 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
GNU grep testsuite comparison: |
| .no_stdout() | ||
| .no_stderr(); | ||
|
|
||
| // In -E mode, hitting the retry limit also yields an error and exit code 2, not a panic. |
There was a problem hiding this comment.
Left the -E case out of the test so #191 can stay open for it.
| /// entire haystack to find the longest. This makes it unsuitable for searching, | ||
| /// but it's perfect for a second, anchored match pass for POSIX semantics. | ||
| longest_anchored: OnigRegex, | ||
| is_pcre: bool, |
There was a problem hiding this comment.
do we need to carry is_pcre through search/match_at/onig_match_result just for the message?
could return a small error enum and pick the text in Matcher, which already has the config
There was a problem hiding this comment.
Done: a MatchError enum is returned, and Matcher picks the text from the config.
| break; | ||
| } | ||
| } | ||
| let raw_matched = any; |
There was a problem hiding this comment.
do we need any and raw_matched?
try_fold or a direct early return would be simpler
There was a problem hiding this comment.
Simplified to a direct early return.
| let res = self | ||
| .leftmost | ||
| .search(line, offset, Some(&mut region), self.is_pcre)?; | ||
| if res.is_some() { |
There was a problem hiding this comment.
Ok(res.and(region.pos(0))), no?
There was a problem hiding this comment.
Yes, now Ok(res.and(region.pos(0))).
| // See: https://github.com/uutils/grep/issues/191 | ||
| let (_s, mut c) = ucmd(); | ||
| c.args(&["-P", "((m+)*)+$"]) | ||
| .pipe_in(format!("{}n\n", "m".repeat(45))) |
There was a problem hiding this comment.
same format!("{}n\n", "m".repeat(45)) 5 times, please put it in a variable
There was a problem hiding this comment.
Pulled into a single variable.
| .no_stdout() | ||
| .stderr_does_not_contain("panicked"); | ||
|
|
||
| // -s suppresses the diagnostic on stderr and still fails with code 2. |
There was a problem hiding this comment.
did you check that GNU really hides this message with -s?
There was a problem hiding this comment.
I left the -s subcase out of the test as well, rather than lock in something I hadn't fully checked against GNU.
4bbd334 to
a16c779
Compare
|
Updated in a16c779:
|
|
GNU grep testsuite comparison: |
a16c779 to
0ee6081
Compare
|
GNU grep testsuite comparison: |
When matching complex regular expressions with nested repetition (such as
((x+)*)+$) against non-matching lines, Oniguruma exhausts its retry limit and returnsONIGERR_RETRY_LIMIT_IN_MATCH_OVER(orONIGERR_MATCH_STACK_LIMIT_OVER).Previously,
onig_match_resultpanicked on any negative return code other thanONIG_MISMATCH, causinguu_grepto abort with SIGABRT (exit 134). GNU grep instead treats this condition as an execution failure, emittinggrep: <file>: exceeded PCRE's backtracking limitand exiting with status 2.This PR propagates Oniguruma matching errors as
io::ErrorthroughMatcher::match_lineandMatcher::is_matchup to the searcher session:onig_match_resultmapsONIGERR_RETRY_LIMIT_IN_MATCH_OVERandONIGERR_MATCH_STACK_LIMIT_OVERtoio::Error::other("exceeded PCRE's backtracking limit")in PCRE mode (-P), orio::Error::other("exceeded backtracking limit")in other modes.Matcher::match_line,Matcher::is_match, andMatchIterpropagate matching errors rather than discarding or panicking.report_io_errorand exits with code 2.Fixes #191