find: reject a non-numeric prefix in the -size argument - #834
Open
AlejandroCoronadoN wants to merge 1 commit into
Open
find: reject a non-numeric prefix in the -size argument#834AlejandroCoronadoN wants to merge 1 commit into
AlejandroCoronadoN wants to merge 1 commit into
Conversation
The -size argument was parsed with an un-anchored regex, so a value like "x5c" or "abc5c" silently matched the "5c" in the middle and was accepted as "5c". The extra sign group also accepted invalid double-sign forms such as "+-5c" and "--5c". Anchor the regex and allow only the one extra '+' that GNU accepts after the comparison sign, so "++5c" and "-+5c" stay valid while the junk-prefix and invalid-sign forms are rejected like GNU find.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #834 +/- ##
==========================================
+ Coverage 91.93% 92.03% +0.10%
==========================================
Files 35 35
Lines 7253 7273 +20
Branches 378 378
==========================================
+ Hits 6668 6694 +26
+ Misses 443 438 -5
+ Partials 142 141 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Commit 7b24ce6 has test result changes: GNU findutils testsuite: bfs testsuite: |
This file contains hidden or 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
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.
Problem
find's-sizeargument was parsed with an un-anchored regex(
([-+]?)[-+]?(\d+)(.*)$), so a non-numeric prefix was silently accepted:GNU
findrejects these withfind: Invalid argument 'x5c' to -size. The extrasign group also accepted
+-5cand--5c, which GNU rejects too.Fix
Anchor the regex at the start and replace the second
[-+]?with\+?, whichmatches GNU's grammar exactly: after the comparison sign GNU accepts one more
optional
+(so++5cand-+5care valid), but not a second-.Verification
Compared against GNU findutils (
gfind) over 13-sizeinputs; exit codes andthe matched file sets are identical:
x5c,abc5c+-5c,--5c,+++5c5c,+5c,-5c,++5c,-+5c-mtime/-inumnumeric parsing is unchanged. Added a unit test; the fullcargo test --libsuite (227 tests) passes andcargo fmt/cargo clippyareclean.