Skip to content

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

Closed

Description

@leeewee

Summary

Running find <file> -ls on a file whose owning UID (or GID) has no entry in /etc/passwd (or /etc/group) panics and exits 101. -ls resolves the owner name with User::from_uid(...), which returns Ok(None) for an unmapped UID; the inner .unwrap() on that Option then panics. GNU find falls back to printing the numeric id instead. This is a routine condition: files from extracted archives that preserve foreign UIDs, NFS mounts, deleted accounts, and container images all produce unmapped owners.

Steps to reproduce

$ ./target/release/find /usr/local/lib/yottadb/r202/COPYING -ls
thread 'main' panicked at src/find/matchers/ls.rs:155:57:
called `Option::unwrap()` on a `None` value
$ echo $?
101

(The host file /usr/local/lib/yottadb/r202/COPYING is owned by UID 228, which has no /etc/passwd entry; any file with an unmapped owning UID reproduces it.)

Expected behavior

Match GNU: print the entry using the numeric uid/gid, no crash, exit 0.

$ /usr/bin/find /usr/local/lib/yottadb/r202/COPYING -ls
  6869904     36 -r--r--r--   1 228      root        34520 Dec  9  2024 /usr/local/lib/yottadb/r202/COPYING
$ echo $?
0

Actual behavior

uutils find panics (Option::unwrap() on None) and exits 101. This triggers for any file whose owning UID lacks a /etc/passwd entry (line 155), and the identical sibling at line 159 triggers for any file whose GID lacks an /etc/group entry. The specific host path above is just one instance; the general portable condition (any unmapped owner/group) is what matters.

Root cause

// src/find/matchers/ls.rs:153
let user = {
    let uid = metadata.uid();
    User::from_uid(Uid::from_raw(uid)).unwrap().unwrap().name
};
let group = {
    let gid = metadata.gid();
    Group::from_gid(Gid::from_raw(gid)).unwrap().unwrap().name
};

User::from_uid / Group::from_gid return Ok(None) when the UID/GID has no passwd/group entry. The outer .unwrap() handles the Result; the inner .unwrap() then panics on the None Option.

Found by source-audit of uutils/findutils.

Activity

  1. leeewee commented on Jul 15, 2026

    @leeewee
    ContributorAuthor

    Duplicate of #692

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions