Skip to content

find panics (parse().unwrap() overflow) on a huge -printf field width #732

Closed

Description

@leeewee

Summary

find … -printf FORMAT aborts (panic, exit 101) when a % directive's field width is a decimal literal larger than usize::MAX.

Steps to reproduce

$ mkdir d; touch d/a
$ find d -printf '%99999999999999999999s\n'
thread 'main' panicked at src/find/matchers/printf.rs:223:45:
called `Result::unwrap()` on an `Err` value: ParseIntError { kind: PosOverflow }
$ echo $?
101

Expected behavior

Match GNU: report the bad width and exit non-zero (1), without crashing.

$ /usr/bin/find d -printf '%99999999999999999999s\n'
find: Value too large for defined data type
$ echo $?
1

Root cause

parse_format_width parses the leading digit run into a usize and unwraps:

// src/find/matchers/printf.rs:223
Some((start[0..digits]).parse().unwrap())

The digit run is validated to be digits but not to fit in usize.

Found by our static analysis tooling.

Activity

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