Skip to content

fix(scanner): decode rg/git output as utf-8 with replacement#55

Merged
emmanuelgjr merged 1 commit into
mainfrom
fix/scan-utf8-decode
Jul 18, 2026
Merged

fix(scanner): decode rg/git output as utf-8 with replacement#55
emmanuelgjr merged 1 commit into
mainfrom
fix/scan-utf8-decode

Conversation

@emmanuelgjr

Copy link
Copy Markdown
Contributor

The bug

subprocess.run(..., text=True) decodes child output with the platform default encoding — cp1252 on Windows, strict UTF-8 on Linux. Any repository containing a file with non-decodable bytes made the CLI raise UnicodeDecodeError and abort the scan. The clean-ASCII fixture never exercised this, so the self-test stayed green while real repos crashed.

Surfaced by the PR-16 benchmark run — the scan of assafelovic/gpt-researcher hit byte 0x8f and died mid-scan.

The fix

Every output-capturing subprocess.run (rg + git; 8 call sites) now passes encoding="utf-8", errors="replace", so undecodable bytes are replaced rather than fatal. Behaviour is otherwise unchanged.

Added a regression test (test_scan_survives_non_utf8_bytes) that writes a file with raw non-UTF-8 bytes and asserts the scan completes without crashing.

Scope

  • cli/dsgai_scan.py — 8 call sites
  • tests/test_runner.py — +1 regression test

No rules, schema, or report changes. Split out from the PR-16 benchmark branch so this fix can be reviewed and merged on its own.

The benchmark surfaced a real cross-platform crash: subprocess.run(text=True) decodes rg/git output with the platform default encoding (cp1252 on Windows, strict utf-8 on Linux), so the CLI raised UnicodeDecodeError on any repo containing a file with non-decodable bytes (hit on assafelovic/gpt-researcher). The clean-ASCII fixture never triggered it.

Fix: every output-capturing subprocess.run now passes encoding='utf-8', errors='replace' (8 call sites). Added a regression test that scans a file with raw non-UTF-8 bytes and asserts no crash. Fixture unchanged (36); 27 tests pass.

Surfaced during PR-16 benchmark prep.
@emmanuelgjr
emmanuelgjr merged commit 26ec83e into main Jul 18, 2026
9 checks passed
@emmanuelgjr
emmanuelgjr deleted the fix/scan-utf8-decode branch July 18, 2026 22:28
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.

1 participant