bug(scan): TrimSpace corrupts valid filenames from git ls-files -z
OpenCodeReview Version
main @ a003b9341a65130b024829101ea35494b56569e1
Operating System
macOS (Apple Silicon)
Installation Method
Built from source
LLM Provider
OpenAI
Bug Description
gitLs correctly requests NUL-delimited paths with git ls-files -z, but then applies strings.TrimSpace(f) to every pathname. Leading and trailing whitespace are valid filename data, not record formatting.
For example, a tracked file named normal.go becomes normal.go. Later Lstat/read operations target the wrong path and the real tracked file is skipped, so a full scan can silently lose coverage.
Steps to Reproduce
-
Create a Git repository containing a tracked Go file with a leading space:
git init printf 'package p\n' > ' normal.go' git add . && git commit -m initial -
Confirm Git preserves the leading byte in its NUL-delimited output:
git -c core.quotepath=false ls-files -z | od -An -tx1c -
Run the scan enumeration path (for example,
ocr scan). -
Observe that
gitLsreturnsnormal.goinstead ofnormal.go; the subsequent filesystem lookup targets a nonexistent path and the tracked file is skipped.
Expected Behavior
NUL-delimited entries should be preserved exactly. After splitting on \x00, the implementation should discard only empty records and must not trim any pathname bytes. The scan should include files with valid leading or trailing whitespace.
Logs / Error Output
The problematic transformation is:
for _, f := range files {
f = strings.TrimSpace(f)
if f != "" {
result = append(result, f)
}
}
AI/LLM Disclosure
- [ ] I didn't use AI/LLM to assist or generate the content above.
Additional Context
Relevant source:
- https://github.com/alibaba/open-code-review/blob/a003b9341a65130b024829101ea35494b56569e1/internal/scan/provider.go#L263-L270
- https://github.com/alibaba/open-code-review/blob/a003b9341a65130b024829101ea35494b56569e1/internal/scan/provider.go#L100-L113
AI/LLM disclosure: This report was prepared with OpenAI Codex (GPT-5) for source inspection and issue drafting. The Git behavior was reproduced locally by the tool; no project code was modified.