Repository navigation
fix(scan): keep NUL-delimited pathnames from git ls-files intact - #1497
Merged
lizhengfeng101 merged 2 commits intoSep 21, 2026
Merged
Conversation
gitLs asks git for NUL-delimited paths and then applies TrimSpace to every record. Leading and trailing spaces are filename bytes, not record framing: " normal.go" became "normal.go", the later Lstat found nothing, and the tracked file left the scan with a warning and no error. A full scan reports success having reviewed one file fewer than the repository holds. The same function also took stdout and stderr combined on the branch every real scan uses, while a comment on the other branch explained why it must not. With -z there is no line structure to resynchronise on, so a warning that git writes while still exiting 0 -- an unreadable directory, for instance -- is glued to the front of the first pathname rather than arriving as a stray record, and that file is renamed out of the scan too. Fixes alibaba#1493
Contributor
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s). |
…orced os.Geteuid cannot identify root on Windows, where it returns -1, and a filesystem mounted without permission support ignores the mode outright. In both cases git reads the directory happily and writes no warning, so the test asserted against a stream that had nothing wrong with it. Reading the directory back answers that for every platform at once. Found by @Qiyuanqiii on alibaba#1490, where the same assumption failed on Windows CI.
This was referenced Sep 21, 2026
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.
Description
gitLsasks git for NUL-delimited paths and then runsstrings.TrimSpaceover every record. Leading and trailing spaces are filename bytes, not record framing —-zexists precisely so that they need no escaping. A trackednormal.gobecamenormal.go, the laterLstatfound nothing, and the file left the scan on a warning. A full scan reports success having reviewed one file fewer than the repository holds.While fixing that I found a second instance of the same defect in the same function.
gitLstakes stdout only on itsp.runner == nilbranch, with a comment explaining why it must:The other branch — the one every real
ocr scantakes, sinceagent.go:319passesa.args.GitRunner— calledRunner.Run, which isCombinedOutput.Runner.Outputalready existed and is now used instead.That one is worse than it sounds. With
-zthere is no line structure to resynchronise on, so a warning git writes while still exiting 0 does not arrive as a stray record: it is glued to the front of the first real pathname. In the test fixture, one unreadable directory costs the scan every file, not one.Type of Change
How Has This Been Tested?
make testpasses locallyTwo new tests in
internal/scan/provider_paths_test.go, both verified to fail without the patch:TestProvider_Enumerate_PreservesWhitespaceInTrackedPathsenumerated ["plain.go"], want [" leading.go" "plain.go" "trailing.go "]TestProvider_Enumerate_StderrWarningIsNotParsedAsAPathenumerated [], want exactly ["kept.go"]The first runs against a real repository through both the
niland injected-Runnerpaths. The second makesgit ls-files --otherswarn and still exit 0 by way of a mode-0000 directory, which is the shape that matters — on a non-zero exitgitLsreturns the error and parses nothing.Both skip on Windows, which normalises away the filenames the fixtures depend on; the second also skips as root, who reads a 0000 directory regardless of its mode. The parsing under test is platform-independent.
One caveat on my local run:
make testuses-race, and this machine's kernel has a 47-bit VMA where ThreadSanitizer needs 48, so every package aborts before running. I ran the suite asgo test -count=1 ./..., which is green, plusmake checkandmake english-check. Race coverage on these changes is therefore untested on my side and rests on CI.Checklist
go fmt,go vet)AI/LLM disclosure: written with AI assistance — Claude Code, model Claude Opus 5. I reviewed every line, and each of the two defects is backed by a test I ran against unpatched
mainto confirm it fails there first. The reasoning above and in any review thread is my own.Related Issues
Closes #1493