You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
find: -printf: advance_one still panics on a multibyte char (after %, \, or a time directive) #730
#723 fixed the -printf octal-escape peek path for multibyte characters, but advance_one still byte-slices and panics when a multibyte character follows a % conversion, a \ escape, or a %A/%C/%T time-field intro.
Steps to reproduce
$ mkdir d; touch d/a
$ find d -printf '%€\n'thread 'main' panicked at src/find/matchers/printf.rs:152:35:byte index 1 is not a char boundary; it is inside '€' (bytes 0..3) of `€`
$ echo$?101Same panic via find d -printf '\€\n' and find d -printf '%A€' (and %C, %T).
Expected (GNU)
$ /usr/bin/find d -printf '%€\n'
find: warning: unrecognized format directive '%€'
%€
$ echo $?
0
Cause
After reading a full char, advance_one drops it by slicing one byte:
// src/find/matchers/printf.rs:150fnadvance_one(&mutself) -> Result<char,Box<dynError>>{let c = self.front()?;self.string = &self.string[1..];// line 152: byte 1 is mid-char for a multibyte `c`Ok(c)}
When c is multibyte, byte index 1 isn't a char boundary, so the slice panics.
PR #817 fixes this. The panic is in advance_one, which is the single shared function used by the % conversion, \\ escape, and %A/%C/%T time-field paths — so fixing it there covers all three reproductions here.
The fix (commit 4dabff7, src/find/matchers/printf.rs) replaces the byte slice with a character-width slice:
fnadvance_one(&mutself) -> Result<char,Box<dynError>>{let c = self.front()?;// Slice off one *character*, not one byte: byte slicing `[1..]` panics// when the next character is multibyte (e.g. a lossy-converted// replacement char from an invalid-UTF-8 argument, or any non-ASCII// character following a `%` directive).self.string = &self.string[c.len_utf8()..];Ok(c)}
Verified against all three repros from this issue (built from the #817 branch):
$ find d -printf '%€\n' # after %
€
€
$ echo 0 # was 101 (panic), now 0
$ find d -printf '\€\n' # after backslash
find: Invalid escape sequence: \€
$ echo 0 # was 101 (panic), now 1 (clean error, no panic)
$ find d -printf '%A€\n' # after time directive
find: Invalid time specifier: %A€
$ echo 0 # was 101 (panic), now 1 (clean error, no panic)
No panic in any case. Happy to split this advance_one change into a focused PR against #730 if the maintainers prefer it separate from the broader invalid-UTF-8-args work in #817 — just say the word.
Activity
MsfPablo commentedon Aug 9, 2026
PR #817 fixes this. The panic is in
advance_one, which is the single shared function used by the%conversion,\\escape, and%A/%C/%Ttime-field paths — so fixing it there covers all three reproductions here.The fix (commit 4dabff7,
src/find/matchers/printf.rs) replaces the byte slice with a character-width slice:Verified against all three repros from this issue (built from the #817 branch):
No panic in any case. Happy to split this
advance_onechange into a focused PR against #730 if the maintainers prefer it separate from the broader invalid-UTF-8-args work in #817 — just say the word.