Repository navigation
Wrapper differential audit: byte-exact argv forwarding, message-safe POSIX-path guard, differential test suite - #6
Merged
Conversation
quote_append() wrapped every argument in literal double quotes, so any
argument containing a quote was mangled by the child CRT parse (embedded
quotes silently stripped from commit -m payloads) and any argument ending
in a backslash reinterpreted the closing quote (backslash became a quote;
when the argument was not last, the unbalanced quote swallowed the next
arguments, aborting e.g. "commit -m X --allow-empty" outright). Trailing
backslash path arguments ("git add D:\dir\") failed hard.
Emit standard Windows command-line quoting instead: quote only when the
argument is empty or contains space/tab/quote; inside quotes double the
backslashes preceding a quote, emit an embedded quote as backslash-quote,
and double trailing backslashes before the closing quote. Size the
command-line buffer from actual content and fail cleanly instead of
silently truncating at a fixed 32 KiB.
Differential suite (49 cases): 3 message-corruption failures before,
0 after. Fixes #4.
Patch 0002 (POSIX-shaped path argument fallback) rewrote every argv
element from argv[1] on, with no notion of which position the argument
occupies. Message payloads are not path arguments, but a message that is
a single token shaped like /x and whose converted Windows path exists got
silently rewritten:
git commit -q --allow-empty -m /c # stored: c:/ (was /c)
git commit -q --allow-empty -m /c/Windows # stored: c:/Windows (was /c/Windows)
git tag -a -m /c v1 # annotation: c:/ (was /c)
Whether a message was rewritten depended on machine state (it fires only
when the converted path exists; e.g. "-m /d" survived on machines that
happen to have a D:\d directory). That breaks git's literal-bytes
contract for commit messages - the same contract issue #3 is about.
Guard the conversion: never rewrite the token following -m or --message
(attached forms -m<val> / --message=<val> are single tokens starting with
"-" and can never match the POSIX-path shape check). -F/--file values are
genuine file paths and keep benefiting from the exists-checked
conversion, so "git commit -F /d/msg.txt" keeps working.
Verified by building git with the updated patch: differential suite
21/21, including the previously-rewritten message and tag-annotation
cases, while add/-F/-C POSIX-path conversion cases still pass.
Fixes #5.
…prefixes
The busybox-style patch(1) shipped in some Windows environments (observed
with the winuxcmd coreutils) mishandles `patch -d <dir> -p1`: it does not
strip the a/ b/ prefixes and dies on the first hunk with
patch: cannot open file '<dir>/b/<file>': No such file or directory
which made scripts/build.py unusable on such hosts. Fall back to
`git apply -p1 --directory=<src>` for these unified diffs; git is always
available in this project's dev/CI environments.
git apply must run from the repo root with a relative --directory:
- --directory rejects absolute paths ("invalid path"), and
- from a subdirectory git sets a prefix and silently skips every patch
path outside it ("Skipped patch '<path>'") while still exiting 0.
Idempotency is preserved: a re-run surfaces "already exists", which is
treated like patch -N's "Skipping patch".
scripts/test-launcher.py runs the same logical command through the launcher (git.exe) and the real mingw64/bin/git.exe in twin repo copies and compares stdout/stderr/exit code plus repo end state (HEAD, commit message bytes, reflog, status) byte-for-byte. Message payloads are additionally asserted against their intended literal bytes, so a bug shared by both stacks (e.g. rewriting "commit -m /c" into "c:/") still fails the suite. Covered: the issue #3 message family (backticks, ${}, $(), zsh-style ${(kv)}), the issue #4 quoting family (embedded quotes, trailing backslash, shell snippets with quoted values), the issue #5 message-as- path family (/c, /d, /d/repo, /D:/repo, tag annotations), CJK/emoji/ multiline/8KB/leading-dash messages, empty messages, and --amend. Identity and dates are frozen so oids are deterministic; target selection via NIUGIT_TEST_ROOT (default: dist/ after a build, installed product as smoke fallback). Current status against a build with both fixes: 21/21 pass; against the 2026-10 installed stack: 15/21 (the six issue #4/#5 regressions fail as intended). Also document the suite and the two fidelity fixes in README.md.
This was referenced Oct 12, 2026
Closed
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.
Wrapper differential audit — pre-release fixes (issues #3, #4, #5)
Full-stack differential audit of the niu-git wrapper, driven by #3 ("wrapper
runs command substitution on commit -m message text"). Same command through
【wrapper
opt/niugit/git.exe】 and 【realmingw64/bin/git.exe】 in twin repocopies; byte-compare stdout/stderr/exit code + repo end state (HEAD, commit
message bytes, reflog, index/status).
Issue #3 verdict: the wrapper does NOT evaluate message text
Reproduced the report through every layer (niubash
sh/niu -c,usr/binmulticall link, launcher, real git) with single-quoted backtick/
${}/$()messages: every layer is byte-transparent, stored commits byte-match. The
reported symptoms (first commit FAILS + backticks executed) reproduce exactly
with double-quoting at the call site — e.g.
git commit -m "note \uname -r`and ${(kv)}"
— which is standard POSIX shell semantics under any shell (niu, Git Bash, GNU bash): the backticks run and${(kv)}raises "bad substitution". Root cause is the composing agent's quoting;-F ` "working" isconsistent (bypasses shell quoting). Detail: comment on #3.
Wrapper-side defects the audit DID find (fixed here):
#4 — launcher re-quoted argv unconditionally (fixed: commit 1)
quote_append()wrapped every argument in literal"...". Args containing"lost the quotes (
she said "hi"→she said hiin a committed message, rc=0);args ending in
\corrupted (ends with backslash \→ends with backslash ";git add 'D:\dir\'failed rc=128); when the mangled arg wasn't last, theunbalanced quote swallowed following args (commit aborted). Now: standard
Windows argv quoting (quote only when empty/contains space-tab-quote; escape
per MSVCRT rules) + content-sized buffer instead of fixed 32 KiB.
#5 — POSIX-path fallback rewrote message args (fixed: commit 2)
Patch 0002 converted every argv element:
commit -m /cstoredc:/,tag -a -m /cstored annotationc:/— silent, and machine-state-dependent(
-m /dsurvived on machines that happen to haveD:\d). Now guarded: valuesfollowing
-m/--messageare never converted (attached forms-m<x>/--message=<x>can't match the shape check). Kept:-Fvalues are realfile paths and still convert (
commit -F /d/msg.txtworks), and path-positionconversion (
git add /d/...,git -C /d/...) is untouched.build fix (commit 3)
busybox-style
patch(1)(winuxcmd) mishandlespatch -d <dir> -p1(does notstrip
a/ b/; dies on first hunk) which madebuild.pyunusable on suchhosts; also
git applysilently skips paths when run from a subdirectory(prefix filter, still exits 0).
apply_patchesnow falls back togit apply -p1 --directory=<rel-src>run from the repo root, idempotent.tests (commit 4)
scripts/test-launcher.py: differential wrapper-vs-real suite + absolutemessage-byte assertions (catches bugs shared by both stacks). 21/21 pass
with this branch's build; 15/21 with the installed 2026-10 stack (the six
failures are exactly the #4/#5 regressions). The wider 49-case audit harness
(URLs ssh://git@/scp-like/file://, config values with CJK paths/equals,
GIT_DIR/GIT_WORK_TREE/GIT_SSH_COMMAND passthrough, exit codes 128/1, bare
invocation/help -a/add -p/hash-object --stdin, CJK filenames, 8KB messages)
is 49/49 PASS with the fixed stack, with the POSIX-path feature cases
(add/-F/-C conversion) all green.
Verification
/W4 /O2 /MT, same flags as CMakeLists).git apply --checkagainst pristinev2.55.0.windows.2 source, then a full local
build/git.exebuild used forthe test runs above.
What needs upstream/other-repo cooperation
usr/bin/git.exewpm multicall link funnels intoopt/niugit/git.exe(proven via GIT_EXEC_PATH sentinel), so fixing thelauncher fixes the product
git; no winuxcmd-side change required for launcher re-quotes argv unconditionally: args with double quotes or trailing backslashes are corrupted (messages and path args alike) #4.-mpayloads (or use
-F)"; nothing to fix in this repo for it.Deployment path (for the release owner)
mastermerge → tag (e.g. v2.55.0.3+) → CI/build.pyartifact zip → wpmindex
wpm/niugit.jsonrehash →wpm install niugitupdates the installedtree (
opt/niugit/git.exe+mingw64/). The installed tree was NOT touchedduring this audit; all verification ran against builds under the audit clone
and NTFS-junction shadow layouts in
testbed/(untracked, local only).Fixes #4, fixes #5; informs #3.