Skip to content

find: -ls: don't panic on an unmapped owner uid/gid - #721

Merged
sylvestre merged 1 commit into
uutils:mainfrom
leeewee:find-fix-ls-unmapped-uid
Jun 10, 2026
Merged

sylvestre merged 1 commit into
uutils:mainfrom
leeewee:find-fix-ls-unmapped-uid

Conversation

@leeewee

@leeewee leeewee commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #717

find <file> -ls panicked (exit 101) when the file's owning uid (or gid) had no /etc/passwd (/etc/group) entry: it resolved the name with User::from_uid(...).unwrap().unwrap(), and the inner unwrap aborts on the Ok(None) that an unmapped id returns. Unmapped owners are routine (extracted archives, NFS, deleted accounts, container images).

Resolve the uid/gid via uucore::entries::uid2usr / gid2grp, falling back to the numeric id when there is no entry, matching GNU find (which prints the number). Per review, this reuses the existing uucore helpers (which serialize the non-thread-safe getpwuid/getgrgid behind a mutex) rather than reimplementing the lookup.

Adds a -ls integration test that chowns a file to an unmapped id and checks the numeric fallback; it skips when the process lacks the privilege to do so.

@codspeed

codspeed Bot commented Jun 9, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 20 untouched benchmarks


Comparing leeewee:find-fix-ls-unmapped-uid (0731a94) with main (001966f)

Open in CodSpeed

@codecov

codecov Bot commented Jun 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.86%. Comparing base (62deaf6) to head (0731a94).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #721      +/-   ##
==========================================
+ Coverage   91.83%   91.86%   +0.02%     
==========================================
  Files          35       35              
  Lines        7129     7153      +24     
  Branches      375      375              
==========================================
+ Hits         6547     6571      +24     
  Misses        437      437              
  Partials      145      145              

☔ 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.

Comment thread src/find/matchers/ls.rs Outdated

use super::{Matcher, MatcherIO, WalkEntry};

/// Resolve a uid to its login name, falling back to the numeric id when the uid

@sylvestre sylvestre Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uucore already has these: entries::uid2usr / gid2grp (feature entries), which also serialize the non-thread-safe getpwuid/getgrgid behind a mutex. please reuse instead of reimplementing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — switched to uucore::entries::uid2usr / gid2grp with the numeric fallback and dropped the hand-rolled helpers. Thanks for the pointer!

@leeewee
leeewee force-pushed the find-fix-ls-unmapped-uid branch from 0d72b62 to a20c696 Compare June 10, 2026 02:26
`find <file> -ls` panicked (exit 101) when the file's owning uid (or gid) had
no `/etc/passwd` (`/etc/group`) entry: it resolved the name with
`User::from_uid(...).unwrap().unwrap()`, and the inner unwrap aborts on the
`Ok(None)` that an unmapped id returns. Unmapped owners are routine (extracted
archives, NFS, deleted accounts, container images).

Resolve the uid/gid via `uucore::entries::uid2usr`/`gid2grp`, falling back to
the numeric id when there is no entry, matching GNU find (which prints the
number). These helpers already serialize the non-thread-safe getpwuid/getgrgid
behind a mutex, so reuse them rather than reimplementing the lookup.

Add a -ls integration test that chowns a file to an unmapped id and checks the
numeric fallback; it skips when the process lacks the privilege to do so.
@leeewee
leeewee force-pushed the find-fix-ls-unmapped-uid branch from a20c696 to 0731a94 Compare June 10, 2026 02:32
@sylvestre
sylvestre merged commit a70f5cc into uutils:main Jun 10, 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.

find panics (unwrap None) on -ls for a file owned by an unmapped UID/GID

2 participants