Repository navigation
grep: reject interval counts above 32767 - #218
yunusarda-sudo wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #218 +/- ##
==========================================
- Coverage 96.89% 96.81% -0.09%
==========================================
Files 6 6
Lines 2160 2196 +36
Branches 235 241 +6
==========================================
+ Hits 2093 2126 +33
- 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:
|
Merging this PR will not alter performance1 warning
Comparing Footnotes
|
| let count = pattern[i..i + digits].iter().try_fold(0u64, |n, &b| { | ||
| n.checked_mul(10)?.checked_add(u64::from(b - b'0')) | ||
| }); | ||
| too_big |= count.is_none_or(|n| n > MAX_INTERVAL_COUNT) && digits > 0; |
There was a problem hiding this comment.
&& digits > 0 is dead: with no digits the fold returns Some(0)
also the loop/continue could be two plain parses (min, optional ,, max), no?
There was a problem hiding this comment.
Fixed in commit fe9c825: simplified to split on , into min and max bounds without the loop, and removed the redundant digits > 0 check.
| let mut too_big = false; | ||
| let mut i = start; | ||
| let mut has_comma = false; | ||
| loop { |
There was a problem hiding this comment.
this loop with a single continue is hard to follow
could you take the body up to close and split it on , instead?
There was a problem hiding this comment.
Done in commit fe9c825: the body up to close is now extracted and split on , directly.
| let count = pattern[i..i + digits].iter().try_fold(0u64, |n, &b| { | ||
| n.checked_mul(10)?.checked_add(u64::from(b - b'0')) | ||
| }); | ||
| too_big |= count.is_none_or(|n| n > MAX_INTERVAL_COUNT) && digits > 0; |
There was a problem hiding this comment.
&& digits > 0 is not needed, no digits gives Some(0)
| /// Whether `pattern` has an interval (`{m,n}` in extended mode, `\{m,n\}` in | ||
| /// basic mode) with a count above [`MAX_INTERVAL_COUNT`]. Oniguruma's own | ||
| /// limit is higher, so GNU's has to be checked here. | ||
| fn has_interval_over_limit(pattern: &[u8], extended: bool) -> bool { |
There was a problem hiding this comment.
almost the same pass as has_confusing_bracket, could it be one pass over the pattern?
There was a problem hiding this comment.
Unified in commit fe9c825: combined into a single precheck_pattern pass handling both confusing brackets and interval limits.
0d6fb93 to
506a5dc
Compare
lhecker
left a comment
There was a problem hiding this comment.
Is it really worth testing for this? The limit seems like a quirk and not like a feature that is inherently needed.
|
The check itself is there to match GNU grep: interval counts above 32767 (POSIX The test is the regression for that bound — including a case that is accepted ( |
|
That's literally what the issue and PR already say. 🫡 Now regarding my point... |
506a5dc to
68e4976
Compare
|
Fair point — dropped the test. |
GNU grep rejects an interval count above 32767, in either bound and in both BRE and ERE, with
Regular expression too big(exit 2). Oniguruma's own limit is 100000, sok{40000}andk{1,40000}were searched.The pattern is now scanned for intervals before compiling (skipping escapes and bracket expressions, reusing
scan_bracket). Braces that don't form an interval ([{]40000}, BREk{40000}, an unclosedk{40000) are left alone.Closes #208