fix(checks): handle multi-byte UTF-8 in package names#9
Open
andrew wants to merge 2 commits into
Open
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Omitted,Repeated,SwappedCharactersandTyposall passed character indices fromchars().enumerate()intoutil::rebuild_name, which slices by byte offset. Any multi-byte codepoint in a package name would panic on a non-char-boundary slice. Switched tochar_indices()so callers always pass valid byte offsets, andlen_utf8()for replace widths.Also adds a
cargo-fuzztarget underfuzz/that feeds arbitrary UTF-8 through aHarnessconfigured with every check. It found the original panic (Omittedon"-ۊ-") in under a second; after the fix it ran ~52k iterations over 60s with no crashes. Run withcargo +nightly fuzz run checks. The fuzz crate is a separate workspace so it doesn't affect MSRV orcargo test.Regression tests with multi-byte inputs added to each fixed check.
Closes #4