Repository navigation
fix: do not panic on non-UTF-8 filenames when matching ignore patterns - #409
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Unconvertible filenames incorrectly bypass wildcard patterns that should exclude them.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Prevents Windows crashes when ignore matching encounters filenames with unpaired surrogates.
Changes:
- Uses fallible path conversion.
- Adds a Windows regression test.
| File | Description |
|---|---|
src/common.rs |
Handles unconvertible paths and tests surrogate-containing names. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
On Windows, NTFS filenames may contain unpaired surrogates that cannot be represented in UTF-8. `IgnorePatterns::is_excluded` converted each entry's relative path with the panicking `gix::path::into_bstr`, so a single such name anywhere in a scanned tree aborted the whole process when `--ignore-from` was used - in list, aggregate and stacks modes alike, as well as in `clean`'s entry filtering. Match on the OS string's encoded bytes instead - `OsStr::as_encoded_bytes` yields a self-synchronizing UTF-8 superset (WTF-8 on Windows, the raw bytes on Unix) which represents lone surrogates losslessly. The glob matcher then compares bytes, so wildcard patterns that don't spell out the invalid code unit, like `*` or `*.txt`, still match such names instead of silently letting them through. Fixes Byron#408
Mathjk
force-pushed
the
fix/ignore-from-nonutf8
branch
from
September 29, 2026 21:15
861a23b to
22d5588
Compare
Owner
|
Thanks a lot! This also reminds of making the |
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.

Fixes #408.
Bug
On Windows, NTFS filenames may legally contain unpaired surrogates (creatable via verbatim paths), which cannot be represented in UTF-8.
IgnorePatterns::is_excludedconverts every walked entry to aBStringvia the panickinggix::path::into_bstr, so a single such filename anywhere in a scanned tree aborts dua (exit 0xC0000409) whenever--ignore-fromis used — in list, aggregate and stacks modes, and inclean's entry filtering too.--ignore-dirsis unaffected (it compares paths directly, no UTF-8 conversion).Fix
Use the fallible
gix::path::try_into_bstrand treat an unconvertible path as not excluded — a path that is not valid UTF-8 can never match a (UTF-8) pattern, so skipping is semantics-preserving.Verification
gix-path/src/convert.rs:80, process abort, on list/aggregate/stacks/cleanfiltering.--ignore-dirsand no-flag paths unchanged.#[cfg(windows)]regression test builds a lone-surrogateOsStringviafrom_wideand assertsis_excludedreturns false instead of panicking;cargo test --lib: 87/87 green.Related sites (out of scope here)
Two other
into_bstruses panic on the same input class —src/clean/git.rs(Git-aware expendable check) andsrc/interactive/widgets/glob.rs(TUI glob search), reachable viadua clean/dua i. Kept them untouched for a minimal diff; happy to cover in this PR or a follow-up — whichever you prefer.