fix(scan): read UTF-16 and Windows-1252 files in the remaining readers (t84) #942

Merged
sharang merged 1 commits from fix/t84-encoding-audit into main 2026-11-09 09:58:55 +00:00
Owner

What

These are the follow-ups from the t84 encoding audit. Five readers still dropped a file silently when it was not UTF-8. They now decode it the way the code graph does since #941: a BOM first (UTF-8, UTF-16 LE/BE), then UTF-8, then Windows-1252. A file with a NUL byte is still treated as binary.

Reader Before Now
GDPR/OAuth pattern scanner (pipeline/patterns.rs) skipped the file scanned; reads only files a pattern applies to
Content fingerprints of findings (pipeline/finding_store.rs) kept the line-based key keyed by content, like UTF-8 files
Control-check surface retrieval (controls/surface.rs) skipped the file file is read
PR review diff (pipeline/git.rs) dropped the line Windows-1252 line decoded
Werkbank PLC program reader (werkbank-exec/src/plc/mod.rs) skipped the file file is read

The decoder moves from compliance-graph to compliance-core (compliance_core::encoding), so the Werkbank runner can use it without depending on the graph crate (tree-sitter, tantivy). All callers now import it from there, and encoding_rs moves with it.

The delegated tools (gitleaks, semgrep, devskim, cppcheck, mobsfscan, syft, clamav, oelint) read files themselves and are not changed. .gitattributes is read as UTF-8 as before.

Effects on stored findings

  • Findings in Windows-1252 or UTF-16 files get a content fingerprint once. Their earlier line-based fingerprint stays in legacy_fingerprints, so the row stored under it is adopted. Nothing is closed or reopened.
  • One-time effect: a finding on line 1 of a UTF-8 file with a BOM was keyed with the BOM character in its content. The BOM is now dropped, so on the first scan after deploy that finding closes and comes back as a new one, and auto-close and issue sync act on it once. This is rare: line 1 is usually using, #include or <?xml.

Tests

  • pattern scanner: a Windows-1252 C# file gives its finding on the right line
  • surface: a Windows-1252 file's region is returned, with "ü" decoded
  • fingerprints: a Windows-1252 file is keyed by content, its line key is kept as legacy, and re-saving the file as UTF-8 keeps the key
  • diff: a Windows-1252 line shows in the hunk
  • Werkbank: a Windows-1252 ST program is extracted
  • decoder tests moved to core, including the doctest

Ran locally:

  • cargo fmt --check
  • clippy -D warnings on core, agent, graph, mcp, werkbank-exec, control-map, and dashboard with server and with web
  • lib tests: 1021 agent and 209 core, plus graph, werkbank-exec and control-map
  • agent integration tests against Mongo: 97 passed, 0 failed

🤖 Generated with Claude Code

## What These are the follow-ups from the t84 encoding audit. Five readers still dropped a file silently when it was not UTF-8. They now decode it the way the code graph does since #941: a BOM first (UTF-8, UTF-16 LE/BE), then UTF-8, then Windows-1252. A file with a NUL byte is still treated as binary. | Reader | Before | Now | |---|---|---| | GDPR/OAuth pattern scanner (`pipeline/patterns.rs`) | skipped the file | scanned; reads only files a pattern applies to | | Content fingerprints of findings (`pipeline/finding_store.rs`) | kept the line-based key | keyed by content, like UTF-8 files | | Control-check surface retrieval (`controls/surface.rs`) | skipped the file | file is read | | PR review diff (`pipeline/git.rs`) | dropped the line | Windows-1252 line decoded | | Werkbank PLC program reader (`werkbank-exec/src/plc/mod.rs`) | skipped the file | file is read | The decoder moves from `compliance-graph` to `compliance-core` (`compliance_core::encoding`), so the Werkbank runner can use it without depending on the graph crate (tree-sitter, tantivy). All callers now import it from there, and `encoding_rs` moves with it. The delegated tools (gitleaks, semgrep, devskim, cppcheck, mobsfscan, syft, clamav, oelint) read files themselves and are not changed. `.gitattributes` is read as UTF-8 as before. ## Effects on stored findings - **Findings in Windows-1252 or UTF-16 files** get a content fingerprint once. Their earlier line-based fingerprint stays in `legacy_fingerprints`, so the row stored under it is adopted. Nothing is closed or reopened. - **One-time effect:** a finding on **line 1 of a UTF-8 file with a BOM** was keyed with the BOM character in its content. The BOM is now dropped, so on the first scan after deploy that finding closes and comes back as a new one, and auto-close and issue sync act on it once. This is rare: line 1 is usually `using`, `#include` or `<?xml`. ## Tests - pattern scanner: a Windows-1252 C# file gives its finding on the right line - surface: a Windows-1252 file's region is returned, with "ü" decoded - fingerprints: a Windows-1252 file is keyed by content, its line key is kept as legacy, and re-saving the file as UTF-8 keeps the key - diff: a Windows-1252 line shows in the hunk - Werkbank: a Windows-1252 ST program is extracted - decoder tests moved to core, including the doctest Ran locally: - `cargo fmt --check` - clippy `-D warnings` on core, agent, graph, mcp, werkbank-exec, control-map, and dashboard with `server` and with `web` - lib tests: 1021 agent and 209 core, plus graph, werkbank-exec and control-map - agent integration tests against Mongo: 97 passed, 0 failed 🤖 Generated with [Claude Code](https://claude.com/claude-code)
sharang added 1 commit 2026-11-09 09:40:54 +00:00
fix(scan): read UTF-16 and Windows-1252 files in the remaining readers (t84)
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Agent integration (pull_request) Successful in 4m24s
CI / Check (pull_request) Successful in 17m38s
664806992e
The t84 audit found five readers that still skipped a file silently when
it was not UTF-8: the GDPR/OAuth pattern scanner, the content
fingerprints of findings, the control-check surface retrieval, the PR
review diff and the Werkbank PLC program reader. They now decode as the
code graph does: BOM, then UTF-8, then Windows-1252.

The decoder moves from compliance-graph to compliance-core, so the
Werkbank runner uses it without pulling in the graph crate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sharang merged commit ca66b9a7b1 into main 2026-11-09 09:58:55 +00:00
Sign in to join this conversation.