Skip to content

find: -printf: reject an over-large field width instead of panicking#734

Open
leeewee wants to merge 1 commit into
uutils:mainfrom
leeewee:find-fix-printf-width-overflow
Open

find: -printf: reject an over-large field width instead of panicking#734
leeewee wants to merge 1 commit into
uutils:mainfrom
leeewee:find-fix-printf-width-overflow

Conversation

@leeewee

@leeewee leeewee commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #732
Fixes #693

A -printf field width could panic two ways:

$ mkdir d; touch d/a
$ find d -printf '%70000s\n'                  # #693
thread 'main' panicked at src/find/matchers/printf.rs:611:37:
Formatting argument out of range

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

parse_format_width is now fallible and rejects both an unparseable (too-large-for-usize) width and any width above u16::MAX, with a graceful error (exit 1) instead of aborting. Widths up to 65535 still pad as before.

Note on the threshold: this rejects any width above u16::MAX (65535), which is below GNU's -printf width ceiling (glibc's printf pads up to near INT_MAX = 2147483647 and errors with EOVERFLOW above it). 65535 is the limit of Rust's core::fmt width argument, so it's where padding can be done without panicking; widths in 65536..INT_MAX that GNU would pad are rejected here rather than emitting up to gigabytes of padding. This keeps the fix minimal and panic-free — a future change could pad those manually to fully match GNU.

Added an integration test (find_printf_width_too_large).

A `-printf` field width could panic two ways: a width above `u16::MAX` reached
`core::fmt`'s `{:>width$}`, which caps the width argument at `u16::MAX` and
panics ("Formatting argument out of range"); and a width above `usize::MAX` was
`.unwrap()`-ed after a failed parse. Make `parse_format_width` fallible and
reject both — an unparseable (too-large-for-`usize`) width, and any width above
`u16::MAX` — with a graceful error instead of aborting.
@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.87%. Comparing base (795d29a) to head (f0ba464).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #734   +/-   ##
=======================================
  Coverage   91.86%   91.87%           
=======================================
  Files          35       35           
  Lines        7153     7160    +7     
  Branches      375      376    +1     
=======================================
+ Hits         6571     6578    +7     
  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.

@codspeed-hq

codspeed-hq Bot commented Jun 12, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 20 untouched benchmarks


Comparing leeewee:find-fix-printf-width-overflow (f0ba464) with main (795d29a)

Open in CodSpeed

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 (parse().unwrap() overflow) on a huge -printf field width bug: find -printf panics issues

1 participant