Skip to content

Commit dfe46c5

Browse files
committed
Merge branch 'jk/loose-object-info-report-error'
Update error handling for codepath that deals with corrupt loose objects. * jk/loose-object-info-report-error: index-pack: detect local corruption in collision check sha1_loose_object_info: return error for corrupted objects
2 parents 3c833ca + 5105417 commit dfe46c5

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

builtin/index-pack.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
810810
unsigned long has_size;
811811
read_lock();
812812
has_type = sha1_object_info(sha1, &has_size);
813+
if (has_type < 0)
814+
die(_("cannot read existing object info %s"), sha1_to_hex(sha1));
813815
if (has_type != type || has_size != size)
814816
die(_("SHA1 COLLISION FOUND WITH %s !"), sha1_to_hex(sha1));
815817
has_data = read_sha1_file(sha1, &has_type, &has_size);

sha1_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2952,7 +2952,7 @@ static int sha1_loose_object_info(const unsigned char *sha1,
29522952
if (status && oi->typep)
29532953
*oi->typep = status;
29542954
strbuf_release(&hdrbuf);
2955-
return 0;
2955+
return (status < 0) ? status : 0;
29562956
}
29572957

29582958
int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi, unsigned flags)

t/t1060-object-corruption.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ test_expect_success 'setup corrupt repo' '
2121
cd bit-error &&
2222
test_commit content &&
2323
corrupt_byte HEAD:content.t 10
24+
) &&
25+
git init no-bit-error &&
26+
(
27+
# distinct commit from bit-error, but containing a
28+
# non-corrupted version of the same blob
29+
cd no-bit-error &&
30+
test_tick &&
31+
test_commit content
2432
)
2533
'
2634

@@ -53,6 +61,13 @@ test_expect_success 'streaming a corrupt blob fails' '
5361
)
5462
'
5563

64+
test_expect_success 'getting type of a corrupt blob fails' '
65+
(
66+
cd bit-error &&
67+
test_must_fail git cat-file -s HEAD:content.t
68+
)
69+
'
70+
5671
test_expect_success 'read-tree -u detects bit-errors in blobs' '
5772
(
5873
cd bit-error &&
@@ -101,4 +116,13 @@ test_expect_failure 'clone --local detects misnamed objects' '
101116
test_must_fail git clone --local misnamed misnamed-checkout
102117
'
103118

119+
test_expect_success 'fetch into corrupted repo with index-pack' '
120+
(
121+
cd bit-error &&
122+
test_must_fail git -c transfer.unpackLimit=1 \
123+
fetch ../no-bit-error 2>stderr &&
124+
test_i18ngrep ! -i collision stderr
125+
)
126+
'
127+
104128
test_done

0 commit comments

Comments
 (0)