Skip to content

mingw: use the full buffer when reading reparse points - #6507

Open
VirgilMing wants to merge 1 commit into
git-for-windows:mainfrom
VirgilMing:codex/mingw-long-symlink-targets
Open

VirgilMing wants to merge 1 commit into
git-for-windows:mainfrom
VirgilMing:codex/mingw-long-symlink-targets

Conversation

@VirgilMing

@VirgilMing VirgilMing commented Oct 22, 2026 •

Copy link
Copy Markdown

This PR fixes #6498.

Before this PR, read_reparse_point() passes MAX_PATH to the UTF-16-to-UTF-8 conversion, while both callers already allocate MAX_LONG_PATH bytes.
The conversion includes the terminating NUL, so the existing code fails with ERANGE (Result too large) for targets of 260 or more UTF-8 bytes.
The failure affects both readlink() and mingw_lstat() independently of core.longpaths; multibyte targets can reach that byte limit with far fewer than 260 characters.

  • This PR changes the conversion's capacity argument to MAX_LONG_PATH, matching the buffers that the callers already allocate.
  • This PR also adds one setup test and six regression cases to the existing t2031-checkout-long-paths.sh script.
    • The new cases cover ASCII and multibyte targets at 259, 260 and 261 UTF-8 bytes.
    • Each new case checks the decoded target, requires both the diff output and stderr to be empty, and verifies the indexed symlink size after git add.
    • The new tests disable the filesystem cache to exercise mingw_lstat() and set core.longpaths=false to demonstrate that the short link pathname does not require that option.
  • The existing buffer allocations and readlink() truncation behavior remain unchanged.

I built the unmodified main code (5cf10d74486d1e59b9ae6cedaedb4e26314e1557) and the patched code on native Windows 11 with MSYS2 UCRT64 GCC 16.2.0.
I used DEVELOPER=1, CFLAGS='-O0 -g' and NO_RUST=1, and disabled optional curl, expat, OpenSSL, gettext, iconv, Perl, Python and Tcl/Tk features for these local validation builds.
Those build settings are not changes in this PR.

I performed the following checks on the original test version, before the index-size assertions added in response to review:

  • I ran the expanded t2031-checkout-long-paths.sh suite against both binaries. Against the unmodified code, four of this PR's new cases fail with Result too large at 260/261 bytes. Against the patched code, all 14 tests pass with no skips: the seven pre-existing tests, the new setup test and the six new regression cases.
  • I reran the existing PowerShell reproducer, which was published before this PR and is not modified or added to the repository by this PR. Its 13 cases complete with both binaries. The unmodified binary produces eight conversion errors on stderr; the patched binary produces no errors or differences. Both script processes exit 0, so I checked stderr explicitly.
  • I ran five other existing, unchanged test scripts against the patched code: t0060-path-utils.sh, t2007-checkout-symlink.sh, t2102-update-index-symlinks.sh, t4011-diff-symlink.sh and t7515-status-symlinks.sh. Together, they execute 219 tests successfully and skip 20 according to their prerequisites. This host's shell ln lacks native symlink support; this PR's new regression cases use Windows mklink, and all six execute successfully.

After the review update, shell syntax, whitespace, ASCII and line-width checks pass. The six target/index-size checks also pass with native Linux symlinks. The updated Windows regression cases have not been rerun locally and still need CI validation.

@VirgilMing
VirgilMing force-pushed the codex/mingw-long-symlink-targets branch from b1e9fbf to bdaf6da Compare November 2, 2026 13:24
@VirgilMing
VirgilMing force-pushed the codex/mingw-long-symlink-targets branch from bdaf6da to b2a0d3a Compare November 28, 2026 14:33
@VirgilMing

Copy link
Copy Markdown
Author

Rebased this single-commit fix onto current main (a4254934167f5a3d8191f3ff7462851e1b896c5a); the updated head is b2a0d3a6efce693634654f24188f450841acad91.

The old run had four cancelled macOS jobs using the unavailable macos-14 runner. Upstream already addressed the runner configuration in f1d6c0c, and all four macos-15 jobs passed in the latest main CI run: https://github.com/git-for-windows/git/actions/runs/46027131145 .

The PR still contains only the original two-file fix and regression tests (43 insertions, 1 deletion). The stable patch ID is unchanged; no workflow changes or test removals were added. Local git diff --check and sh -n t/t2031-checkout-long-paths.sh pass. I have not rerun the Windows regression tests locally on this Linux host.

The new CI, check-style, and check-whitespace workflows were triggered by this update but are awaiting maintainer approval. Could a maintainer please approve the runs so the refreshed branch can be tested?

CI run: https://github.com/git-for-windows/git/actions/runs/46155273486

@dscho dscho left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I will probably not get to merging this before v2.98.0-rc1, but with this one change, I think this PR is good to go!

Comment thread t/t2031-checkout-long-paths.sh Outdated
test_cmp expect actual &&
git diff --exit-code -- long-link >actual 2>err &&
test_must_be_empty actual &&
test_must_be_empty err

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe assert the index size? The existing tests detect lstat() failure but can mask an incorrect nonzero size:

diff --git a/t/t2031-checkout-long-paths.sh b/t/t2031-checkout-long-paths.sh
--- a/t/t2031-checkout-long-paths.sh
+++ b/t/t2031-checkout-long-paths.sh
@@ -145,7 +145,10 @@ do
 			test_cmp expect actual &&
 			git diff --exit-code -- long-link >actual 2>err &&
 			test_must_be_empty actual &&
-			test_must_be_empty err
+			test_must_be_empty err &&
+			git add -- long-link &&
+			git ls-files --debug -- long-link >actual &&
+			test_grep "^  size: $bytes[^0-9]" actual
 		'
 	done
 done

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dscho Added the index-size assertions in 69f6503 exactly as suggested. Could you please take another look?

Local syntax/format checks and all six Linux target/index-size checks pass. The updated Windows cases are awaiting CI approval.

read_reparse_point() limits its UTF-16 to UTF-8 conversion to MAX_PATH
bytes, although both callers provide a MAX_LONG_PATH-sized buffer. Since
the conversion includes the terminating NUL, symlink targets of 260 or
more UTF-8 bytes fail with ERANGE. This affects both readlink() and
mingw_lstat(), even for short link paths and with core.longpaths enabled.

Use MAX_LONG_PATH for the conversion, matching the buffers allocated by
the callers. Add Windows regression coverage for ASCII and multibyte
targets of 259, 260 and 261 bytes. Check the decoded target as well as the
diff output and stderr, since git diff can report the conversion error
without failing its exit status. Disable the filesystem cache so the
tests also exercise mingw_lstat().

Also assert the indexed symlink size after git add, since a clean diff
can mask an incorrect nonzero size returned by mingw_lstat().

Fixes: git-for-windows#6498
Co-authored-by: GPT-6
Signed-off-by: vgm <virgilming@gmail.com>
@VirgilMing
VirgilMing force-pushed the codex/mingw-long-symlink-targets branch from b2a0d3a to 69f6503 Compare December 2, 2026 04:52

This branch has not been deployed

No deployments
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.

Regression: symlink targets >= 260 UTF-8 bytes fail with "Result too large" despite core.longpaths=true

2 participants