Skip to content

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

Open
AlejandroCoronadoN wants to merge 1 commit into
uutils:mainfrom
AlejandroCoronadoN:fix-size-nonnumeric-prefix
Open

find: reject a non-numeric prefix in the -size argument#834
AlejandroCoronadoN wants to merge 1 commit into
uutils:mainfrom
AlejandroCoronadoN:fix-size-nonnumeric-prefix

Conversation

@AlejandroCoronadoN

Copy link
Copy Markdown

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.

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

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.03%. Comparing base (5aa8184) to head (7b24ce6).
⚠️ Report is 1 commits behind head on main.

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.
📢 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-hq

codspeed-hq 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 (7b24ce6) with main (5aa8184)

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

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.

1 participant