Skip to content

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

@leeewee

Description

@leeewee

#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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions