Skip to content

find: -printf: don't panic on a multibyte char after an octal escape#723

Merged
sylvestre merged 1 commit into
uutils:mainfrom
leeewee:find-fix-printf-octal-escape
Jun 9, 2026
Merged

find: -printf: don't panic on a multibyte char after an octal escape#723
sylvestre merged 1 commit into
uutils:mainfrom
leeewee:find-fix-printf-octal-escape

Conversation

@leeewee

@leeewee leeewee commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Fixes #720

find -printf '\NNN' octal escapes were parsed by slicing a fixed 3 bytes off the format string. When fewer than 3 octal digits are followed by a multibyte character (e.g. -printf '\0€'), that 3-byte slice lands inside the multibyte char and panics on a UTF-8 char-boundary assertion (exit 101); GNU find exits 0.

The octal escape is now parsed from its leading octal digits only (1 to 3, all ASCII) and the parser advances by their byte length, so a following multibyte char is never sliced into.

This also fixes \1..\7: previously only \0 was recognised and \1..\7 fell through to the single-character escape table and errored, instead of being treated as octal — now matching GNU find.

Verified byte-for-byte against GNU for \0€, \1😀, \00é, \101, \012X. Added a regression unit test.

`\NNN` octal escapes were parsed by slicing a fixed 3 bytes off the
format string, which panics when fewer than 3 octal digits are followed
by a multibyte character (e.g. `-printf '\0€'`): the 3-byte slice lands
inside the multibyte char and trips a char-boundary assertion.

Parse the octal escape from the leading octal digits only (1 to 3, all
ASCII) and advance by their byte length. This also fixes `\1`..`\7`,
which previously fell through to the single-character escape table and
errored instead of being treated as octal, matching GNU find.
@sylvestre

Copy link
Copy Markdown
Contributor

thanks for also proposing PR !
could you please also add a test in :
tests/test_find.rs

@codspeed-hq

codspeed-hq Bot commented Jun 9, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 20 untouched benchmarks


Comparing leeewee:find-fix-printf-octal-escape (c705f5f) with main (865ab09)

Open in CodSpeed

@codecov

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.42857% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.84%. Comparing base (62deaf6) to head (c705f5f).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/find/matchers/printf.rs 96.42% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #723   +/-   ##
=======================================
  Coverage   91.83%   91.84%           
=======================================
  Files          35       35           
  Lines        7129     7149   +20     
  Branches      375      375           
=======================================
+ Hits         6547     6566   +19     
- Misses        437      438    +1     
  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.

@sylvestre sylvestre merged commit 5398003 into uutils:main Jun 9, 2026
23 checks passed
sylvestre pushed a commit that referenced this pull request Jun 10, 2026
Regression test for the panic fixed in #720/#723: a `\NNN` octal escape
immediately followed by a multibyte character (`\0€`) used to slice the
format string mid-char and abort. Assert `-printf` emits the escape byte
and the following character intact.
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 (str char-boundary) on a multibyte char after an octal escape in -printf

2 participants