Skip to content

fix(checks): handle multi-byte UTF-8 in package names#9

Open
andrew wants to merge 2 commits into
rustfoundation:mainfrom
andrew:feat/fuzz
Open

fix(checks): handle multi-byte UTF-8 in package names#9
andrew wants to merge 2 commits into
rustfoundation:mainfrom
andrew:feat/fuzz

Conversation

@andrew
Copy link
Copy Markdown

@andrew andrew commented May 11, 2026

Omitted, Repeated, SwappedCharacters and Typos all passed character indices from chars().enumerate() into util::rebuild_name, which slices by byte offset. Any multi-byte codepoint in a package name would panic on a non-char-boundary slice. Switched to char_indices() so callers always pass valid byte offsets, and len_utf8() for replace widths.

Also adds a cargo-fuzz target under fuzz/ that feeds arbitrary UTF-8 through a Harness configured with every check. It found the original panic (Omitted on "-ۊ-") in under a second; after the fix it ran ~52k iterations over 60s with no crashes. Run with cargo +nightly fuzz run checks. The fuzz crate is a separate workspace so it doesn't affect MSRV or cargo test.

Regression tests with multi-byte inputs added to each fixed check.

Closes #4

andrew added 2 commits May 11, 2026 15:45
Omitted, Repeated, SwappedCharacters and Typos all passed character
indices from chars().enumerate() into util::rebuild_name, which
slices by byte offset. Any multi-byte codepoint in the input would
panic on a non-char-boundary slice.

Switch to char_indices() so callers always pass valid byte offsets,
and use len_utf8() for replace lengths where the replaced character
may be wider than one byte.

Closes rustfoundation#4
Feeds arbitrary UTF-8 strings as package names through a Harness
configured with every check, against a small fixed corpus so that
match paths are also exercised.

Found the multi-byte slice panic fixed in the previous commit
within the first second of running.

Run with:

    cargo +nightly fuzz run checks
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.

Checks may not be UTF-8 safe

1 participant