[v6] plumbing: format/index, Improve v4 entry name validation#1934
Merged
pjbgf merged 4 commits intogo-git:mainfrom Mar 28, 2026
Merged
[v6] plumbing: format/index, Improve v4 entry name validation#1934pjbgf merged 4 commits intogo-git:mainfrom
pjbgf merged 4 commits intogo-git:mainfrom
Conversation
Signed-off-by: Paulo Gomes <paulo@entire.io>
Convert all IndexSuite-based tests to standalone Test functions so they actually execute. The suite had no runner, so these tests were silently skipped. Also fix the hash mismatch (SHA256 was used to decode SHA1 fixtures). Additionally, simplify unknownExtensionDecoder.Decode to use io.Copy. Signed-off-by: Paulo Gomes <paulo@entire.io> Assisted-by: Claude Opus 4.6 <noreply@anthropic.com>
…with Git The V2/V3 decoder truncated entry names longer than 4095 bytes because it trusted the 12-bit length field. Git falls back to strlen (scanning for the NUL terminator) when the field is saturated at 0xFFF; do the same here so long paths round-trip correctly. The V4 encoder used a path.Dir heuristic for prefix compression, which diverges from Git's byte-level longest-common-prefix algorithm. Replace it with a common-prefix computation so the output matches what upstream produces. Signed-off-by: Paulo Gomes <paulo@entire.io> Assisted-by: Claude Opus 4.6 <noreply@anthropic.com>
The treeExtensionDecoder.readEntry early-returned on invalidated entries (entry_count == -1) before consuming the subtree count and newline, leaving stale bytes in the stream that corrupted subsequent entries. Move the invalidation check after fully parsing the entry line so the reader is always left at the correct position. Signed-off-by: Paulo Gomes <paulo@entire.io>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Git index (plumbing/format/index) encoder/decoder to better match on-disk edge cases, especially around V4 name prefix-compression and long entry names whose lengths overflow the V2/V3 flags length field, and adds regression tests to lock in the behavior.
Changes:
- Fix V4 entry name encoding to use true common-prefix compression (rather than directory-based heuristics).
- Improve V2/V3 name decoding when flags name length is
0xFFFby scanning for the NUL terminator and adjusting padding consumption accordingly. - Add/expand regression tests for long names, V4 strip-length validation, patched flags behavior, TREE invalidated entries, and fixture coverage across index versions.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| plumbing/format/index/index_test.go | Refactors tests away from testify suite into standard testing + assert/require with parallelization. |
| plumbing/format/index/encoder_test.go | Adds an encode/decode regression test for long entry names overflowing the 12-bit flags length field. |
| plumbing/format/index/encoder.go | Reworks V4 entry name prefix-compression logic to use longest common prefix and writes the correct strip length + suffix. |
| plumbing/format/index/decoder_test.go | Adds comprehensive regression tests for V4 strip-length validation, 0xFFF name-length fallback behavior, fixtures coverage, and TREE invalidated entry parsing. |
| plumbing/format/index/decoder.go | Implements long-name NUL-scan fallback for V2/V3, validates V4 strip length, fixes TREE invalidated entry parsing, and simplifies unknown extension draining. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Updates Git index (
plumbing/format/index) encoding/decoding logic to better match on-disk format edge cases (long entry names and V4 name prefix-compression), and adds regression tests around these behaviors.Relates to #1868.