codex-security icon indicating copy to clipboard operation
codex-security copied to clipboard

Diff ranking still decodes Git filenames with the Windows locale

Open sylvesterkaczmarek opened this issue 3 months ago • 1 comments

Summary

generate_rank_input.py still invokes Git with text=True and no explicit encoding in both diff-path enumeration and untracked-file enumeration:

subprocess.run(... "git", "diff", "--name-status", "-z", ..., text=True)
subprocess.run(... "git", "ls-files", "--others", ..., "-z", text=True)

Python therefore decodes Git's output with the process locale. On Windows with a non-UTF-8 ANSI code page, a repository containing non-ASCII filenames can be decoded incorrectly or raise UnicodeDecodeError before diff ranking starts.

Scope

This is separate from #192 / PR #226, which address text-mode Git decoding in the bundled workbench helper. generate_rank_input.py launches Git directly and does not use that helper for these two path-list operations.

A previously closed proposal, PR #293, identified this second call site while fixing #192 and explicitly offered to split it. The current main still has both locale-dependent calls.

Impact

Committed diff scans can fail while reading git diff --name-status -z when a changed file has a non-ASCII name. Working-tree diff scans have the same exposure in both that command and git ls-files --others --exclude-standard -z for untracked files.

The checkout path itself can be ASCII; only a changed filename needs non-ASCII characters.

Expected behavior

Decode Git's text output explicitly as UTF-8, matching Git's path output and the direction already taken for the workbench Git helper.

Suggested fix

Pass encoding="utf-8" to both text-mode subprocess calls and add a focused regression that instruments the helper's Git subprocess boundary to require UTF-8 decoding for diff and untracked path enumeration.

sylvesterkaczmarek avatar Aug 18 '26 00:08 sylvesterkaczmarek

Merged PR #501 ("fix: enforce UTF-8 at Windows process boundaries", 5cee678) looks like it already resolved this, and went further than the suggested fix.

On current main (f222faf), neither call site named in this issue runs in text mode any more, so Python's locale decoder is no longer involved at all:

  • run_git_changed_paths (generate_rank_input.py:628) invokes git diff --name-status -z with capture_output=True and no text=True, splits result.stdout on b"\0", and decodes each pathname with os.fsdecode (line 654).
  • The untracked-file enumeration (line 666) invokes git ls-files --others --exclude-standard -z the same way and decodes with os.fsdecode (line 674).

Since text=True is gone from both, the ANSI-code-page misdecode and UnicodeDecodeError described here are no longer reachable. os.fsdecode resolves to UTF-8 on Windows, which matches Git's pathname output.

That also leaves PR #543 with nothing to change: it adds encoding="utf-8" to text=True invocations that no longer exist, and it is currently conflicting against main.

Suggest closing this issue, and closing #543 as superseded by #501.

rohanpoudel2 avatar Aug 21 '26 23:08 rohanpoudel2