forked from git/git
-
Notifications
You must be signed in to change notification settings - Fork 189
Duplicate entry hardening #2096
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
newren
wants to merge
5
commits into
gitgitgadget:master
Choose a base branch
from
newren:duplicate-entry-hardening
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dc0f596
merge-ort: propagate callback errors from traverse_trees_wrapper()
newren b4ff725
merge-ort: drop unnecessary show_all_errors from collect_merge_info()
newren 673fbea
merge-ort: free diff pairs queue in clear_or_reinit_internal_opts()
newren b542124
merge-ort: abort merge when trees have duplicate entries
newren cf50f1a
cache-tree: fix verify_cache() to catch non-adjacent D/F conflicts
newren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| #!/usr/bin/perl | ||
| # | ||
| # Build a v2 index file from entries listed on stdin. | ||
| # Each line: "octalmode hex-oid name" | ||
| # Output: binary index written to stdout. | ||
| # | ||
| # This bypasses all D/F safety checks in add_index_entry(), simulating | ||
| # what happens when code uses ADD_CACHE_JUST_APPEND to bulk-load entries. | ||
| use strict; | ||
| use warnings; | ||
| use Digest::SHA qw(sha1 sha256); | ||
|
|
||
| my $hash_algo = $ENV{'GIT_DEFAULT_HASH'} || 'sha1'; | ||
| my $hash_func = $hash_algo eq 'sha256' ? \&sha256 : \&sha1; | ||
|
|
||
| my @entries; | ||
| while (my $line = <STDIN>) { | ||
| chomp $line; | ||
| my ($mode, $oid_hex, $name) = split(/ /, $line, 3); | ||
| push @entries, [$mode, $oid_hex, $name]; | ||
| } | ||
|
|
||
| my $body = "DIRC" . pack("NN", 2, scalar @entries); | ||
|
|
||
| for my $ent (@entries) { | ||
| my ($mode, $oid_hex, $name) = @{$ent}; | ||
| # 10 x 32-bit stat fields (zeroed), with mode in position 7 | ||
| my $stat = pack("N10", 0, 0, 0, 0, 0, 0, oct($mode), 0, 0, 0); | ||
| my $oid = pack("H*", $oid_hex); | ||
| my $flags = pack("n", length($name) & 0xFFF); | ||
| my $entry = $stat . $oid . $flags . $name . "\0"; | ||
| # Pad to 8-byte boundary | ||
| while (length($entry) % 8) { $entry .= "\0"; } | ||
| $body .= $entry; | ||
| } | ||
|
|
||
| binmode STDOUT; | ||
| print $body . $hash_func->($body); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| #!/bin/sh | ||
|
|
||
| test_description='verify_cache() must catch non-adjacent D/F conflicts | ||
|
|
||
| Ensure that verify_cache() can complain about bad entries like: | ||
|
|
||
| docs <-- submodule | ||
| docs-internal/... <-- sorts here because "-" < "/" | ||
| docs/... <-- D/F conflict with "docs" above, not adjacent | ||
|
|
||
| In order to test verify_cache, we directly construct a corrupt index | ||
| (bypassing the D/F safety checks in add_index_entry) and verify that | ||
| write-tree rejects it. | ||
| ' | ||
|
|
||
| . ./test-lib.sh | ||
|
|
||
| if ! test_have_prereq PERL | ||
| then | ||
| skip_all='skipping verify_cache D/F tests; Perl not available' | ||
| test_done | ||
| fi | ||
|
|
||
| # Build a v2 index from entries on stdin, bypassing D/F checks. | ||
| # Each line: "octalmode hex-oid name" (entries must be pre-sorted). | ||
| build_corrupt_index () { | ||
| perl "$TEST_DIRECTORY/t0093-direct-index-write.pl" >"$1" | ||
| } | ||
|
|
||
| test_expect_success 'setup objects' ' | ||
| test_commit base && | ||
| BLOB=$(git rev-parse HEAD:base.t) && | ||
| SUB_COMMIT=$(git rev-parse HEAD) | ||
| ' | ||
|
|
||
| test_expect_success 'adjacent D/F conflict is caught by verify_cache' ' | ||
| cat >index-entries <<-EOF && | ||
| 0160000 $SUB_COMMIT docs | ||
| 0100644 $BLOB docs/requirements.txt | ||
| EOF | ||
| build_corrupt_index .git/index <index-entries && | ||
|
|
||
| test_must_fail git write-tree 2>err && | ||
| test_grep "You have both docs and docs/requirements.txt" err | ||
| ' | ||
|
|
||
| test_expect_success 'non-adjacent D/F conflict is caught by verify_cache' ' | ||
| cat >index-entries <<-EOF && | ||
| 0160000 $SUB_COMMIT docs | ||
| 0100644 $BLOB docs-internal/README.md | ||
| 0100644 $BLOB docs/requirements.txt | ||
| EOF | ||
| build_corrupt_index .git/index <index-entries && | ||
|
|
||
| test_must_fail git write-tree 2>err && | ||
| test_grep "You have both docs and docs/requirements.txt" err | ||
| ' | ||
|
|
||
| test_done |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Junio C Hamano wrote on the Git mailing list (how to reply to this email):