Skip to content

touch panics (str char-boundary) on a multibyte char in a -t timestamp #12618

@leeewee

Description

@leeewee

Summary

Running touch -t <TS> with a timestamp whose character count is 10 or 13 and whose first character is a multi-byte UTF-8 character panics. parse_timestamp dispatches on s.chars().count(), but prepend_century slices s[..2] by bytes; when the leading character is wider than one byte the slice lands inside a character and Rust aborts with a char-boundary panic (exit 134). GNU rejects the same input with invalid date format and exits 1.

Steps to reproduce

$ touch -t '€123456789' /tmp/tf
thread 'main' panicked at src/uu/touch/src/touch.rs:744:29:
byte index 2 is not a char boundary; it is inside '€' ...
$ echo $?
134

Expected behavior

Match GNU: report the error and exit non-zero without crashing.

$ /usr/bin/touch -t '€123456789' /tmp/tf
/usr/bin/touch: invalid date format '€123456789'
$ echo $?
1

Actual behavior

uutils panics with byte index 2 is not a char boundary and aborts with exit code 134, instead of reporting an invalid date format. Triggered when the -t value's character count is 10 or 13 (the lengths routed through century prepending) and its first character is more than 2 bytes wide.

Found by our static analysis tooling.

Metadata

Metadata

Assignees

No one assigned

    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