Skip to content

findutils: a non-UTF-8 argument aborts every binary (find, locate, xargs, updatedb) #767

Description

@leeewee

All four findutils binaries collect their arguments with std::env::args().collect::<Vec<String>>(). std::env::args() panics when any argument is not valid Unicode (it is documented as such, and internally unwraps the OsString → String conversion). Since Unix paths are arbitrary byte strings — not necessarily UTF-8 — passing a filename that isn't valid UTF-8 aborts the process before any work is done:

site code
src/find/main.rs:13 let args = std::env::args().collect::<Vec<String>>();
src/locate/main.rs:6 (identical)
src/xargs/main.rs:8 (identical)
src/updatedb/main.rs:6 (identical)
$ find $'\xff'
thread 'main' panicked at library/std/src/env.rs:879:51:
called `Result::unwrap()` on an `Err` value: "\xFF"
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
$ echo $?
101

GNU findutils, same input:

$ /usr/bin/find $'\xff'
/usr/bin/find: ‘\377’: No such file or directory
$ echo $?
1

All four binaries abort identically (<bin> $'\xff' → exit 101): find, locate, xargs, updatedb.

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