Skip to content

stat: fix char-boundary panic on an invalid directive after a multibyte char#12617

Open
leeewee wants to merge 1 commit into
uutils:mainfrom
leeewee:stat-fix-directive-char-boundary
Open

stat: fix char-boundary panic on an invalid directive after a multibyte char#12617
leeewee wants to merge 1 commit into
uutils:mainfrom
leeewee:stat-fix-directive-char-boundary

Conversation

@leeewee
Copy link
Copy Markdown
Contributor

@leeewee leeewee commented Jun 5, 2026

Fixes #12616

stat -c '€%-' (a multibyte char before an invalid % directive) aborted with "byte index N is not a char boundary": check_bound byte-sliced the format string using char indices, splitting the multibyte char.

Build the directive substring by chars instead of byte-slicing, so the invalid directive is reported (exit 1) like GNU instead of crashing. Adds a regression test.

…te char

`stat -c '€%-'` (a multibyte char immediately before an invalid `%`
directive) aborted with "byte index N is not a char boundary". The format
parser tracks positions as char indices, but `check_bound` built its
"invalid directive" message by byte-slicing the format string, so a
preceding multibyte char made the byte index land mid-UTF-8.

Build the directive substring by chars instead of byte-slicing, so the
invalid-directive error is reported (exit 1) like GNU instead of crashing.
@leeewee leeewee force-pushed the stat-fix-directive-char-boundary branch from 3d92d37 to 1bb9ea7 Compare June 5, 2026 05:38
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 5, 2026

GNU testsuite comparison:

Congrats! The gnu test tests/dd/no-allocate is now passing!
Congrats! The gnu test tests/seq/seq-epipe is now passing!

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.

stat panics (str char-boundary) on a multibyte char before an invalid % directive

1 participant