find: -printf: advance_one still panics on a multibyte char (after %, \, or a time directive)

Open Beginner friendly
#730 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
84/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
rust
Domain
cli

Research direction

Start in src/find/matchers/printf.rs at advance_one and inspect how printf parsing consumes characters after %, \, and %A/%C/%T. Reproduce the issue with the find commands shown, then verify that multibyte characters no longer panic and that the output and exit status match the expected GNU behavior.

Written by the indexing model from the issue text.

Description

#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 $?
101
Same 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:150
fn advance_one(&mut self) -> Result<char, Box<dyn Error>> {
    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.

Dominant language
Rust
Stars
649
Forks
101
Avg merge
2d 21h
Merged PRs (30d)
11

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from uutils/findutils

All issues in uutils/findutils

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.