Skip to content

Commit 3d12d0c

Browse files
Johannes SixtJunio C Hamano
authored andcommitted
Catch errors when writing an index that contains invalid objects.
If git-write-index is called without --missing-ok, it reports invalid objects that it finds in the index. But without this patch it dies right away or may run into an infinite loop. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 40cf043 commit 3d12d0c

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

cache-tree.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ static int update_one(struct cache_tree *it,
282282
baselen + sublen + 1,
283283
missing_ok,
284284
dryrun);
285+
if (subcnt < 0)
286+
return subcnt;
285287
i += subcnt - 1;
286288
sub->used = 1;
287289
}

t/t0000-basic.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,28 @@ test_expect_success \
209209
'validate object ID for a known tree.' \
210210
'test "$ptree" = 3c5e5399f3a333eddecce7a9b9465b63f65f51e2'
211211

212+
cat >badobjects <<EOF
213+
100644 blob 1000000000000000000000000000000000000000 dir/file1
214+
100644 blob 2000000000000000000000000000000000000000 dir/file2
215+
100644 blob 3000000000000000000000000000000000000000 dir/file3
216+
100644 blob 4000000000000000000000000000000000000000 dir/file4
217+
100644 blob 5000000000000000000000000000000000000000 dir/file5
218+
EOF
219+
220+
rm .git/index
221+
test_expect_success \
222+
'put invalid objects into the index.' \
223+
'git-update-index --index-info < badobjects'
224+
225+
test_expect_failure \
226+
'writing this tree without --missing-ok.' \
227+
'git-write-tree'
228+
229+
test_expect_success \
230+
'writing this tree with --missing-ok.' \
231+
'git-write-tree --missing-ok'
232+
233+
212234
################################################################
213235
rm .git/index
214236
test_expect_success \

0 commit comments

Comments
 (0)