Skip to content

find: reject a non-numeric prefix in the -size argument - #834

Merged
sylvestre merged 1 commit into
uutils:mainfrom
AlejandroCoronadoN:fix-size-nonnumeric-prefix
Aug 18, 2026
Merged

sylvestre merged 1 commit into
uutils:mainfrom
AlejandroCoronadoN:fix-size-nonnumeric-prefix

Conversation

@AlejandroCoronadoN

Copy link
Copy Markdown
Contributor

Problem

find's -size argument was parsed with an un-anchored regex
(([-+]?)[-+]?(\d+)(.*)$), so a non-numeric prefix was silently accepted:

$ find . -size x5c      # matched as if it were "-size 5c"
$ find . -size abc5c    # same

GNU find rejects these with find: Invalid argument 'x5c' to -size. The extra
sign group also accepted +-5c and --5c, which GNU rejects too.

Fix

Anchor the regex at the start and replace the second [-+]? with \+?, which
matches GNU's grammar exactly: after the comparison sign GNU accepts one more
optional + (so ++5c and -+5c are valid), but not a second -.

Verification

Compared against GNU findutils (gfind) over 13 -size inputs; exit codes and
the matched file sets are identical:

input before after / GNU
x5c, abc5c accepted rejected
+-5c, --5c, +++5c accepted rejected
5c, +5c, -5c, ++5c, -+5c accepted accepted (same comparison)

-mtime/-inum numeric parsing is unchanged. Added a unit test; the full
cargo test --lib suite (227 tests) passes and cargo fmt / cargo clippy are
clean.

@codecov

codecov Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.09%. Comparing base (9e778f1) to head (5b798e1).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #834      +/-   ##
==========================================
+ Coverage   92.01%   92.09%   +0.08%     
==========================================
  Files          35       35              
  Lines        7316     7316              
  Branches      378      378              
==========================================
+ Hits         6732     6738       +6     
+ Misses        442      437       -5     
+ Partials      142      141       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed

codspeed Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 20 untouched benchmarks


Comparing AlejandroCoronadoN:fix-size-nonnumeric-prefix (5b798e1) with main (9e778f1)

Open in CodSpeed

@github-actions

Copy link
Copy Markdown

Commit 7b24ce6 has test result changes:

GNU findutils testsuite:

Test results comparison:
  Current:   TOTAL: 495 / PASSED: 418 / FAILED: 76 / SKIPPED: 1
  Reference: TOTAL: 495 / PASSED: 417 / FAILED: 77 / SKIPPED: 1

Changes from main branch:
  TOTAL: +0
  PASSED: +1
  FAILED: -1

Test improvements (1):
  + size-invalid.new-O3

bfs testsuite:

Test results comparison:
  Current:   TOTAL: 314 / PASSED: 267 / FAILED: 41 / SKIPPED: 6
  Reference: TOTAL: 313 / PASSED: 267 / FAILED: 40 / SKIPPED: 6

Changes from main branch:
  TOTAL: +1
  PASSED: +0
  FAILED: +1

New test failures (1):
  - gnu/files0_from_ok

@sylvestre

Copy link
Copy Markdown
Contributor

please add a test_find.rs

The -size argument was parsed with an un-anchored regex, so "x5c" or "abc5c"
silently matched the "5c" in the middle. Anchor the regex and allow only the
one extra '+' GNU accepts after the comparison sign, so "++5c"/"-+5c" stay valid
while the junk-prefix and invalid-sign forms are rejected. Adds a test_find.rs
test.
@AlejandroCoronadoN
AlejandroCoronadoN force-pushed the fix-size-nonnumeric-prefix branch from 7b24ce6 to 5b798e1 Compare August 17, 2026 14:13
@AlejandroCoronadoN

Copy link
Copy Markdown
Contributor Author

Done, added an integration test in test_find.rs covering the rejected and accepted -size forms.

@github-actions

Copy link
Copy Markdown

Commit 5b798e1 has test result changes:

GNU findutils testsuite:

Test results comparison:
  Current:   TOTAL: 495 / PASSED: 421 / FAILED: 73 / SKIPPED: 1
  Reference: TOTAL: 495 / PASSED: 420 / FAILED: 74 / SKIPPED: 1

Changes from main branch:
  TOTAL: +0
  PASSED: +1
  FAILED: -1

Test improvements (1):
  + size-invalid.new-O3

bfs testsuite:

Test results comparison:
  Current:   TOTAL: 313 / PASSED: 267 / FAILED: 40 / SKIPPED: 6
  Reference: TOTAL: 314 / PASSED: 266 / FAILED: 42 / SKIPPED: 6

Changes from main branch:
  TOTAL: -1
  PASSED: +1
  FAILED: -2

Test improvements (2):
  + gnu/files0_from_ok
  + gnu/okdir_path_empty

@sylvestre
sylvestre merged commit 6e4a7fb into uutils:main Aug 18, 2026
22 checks passed
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.

2 participants