Skip to content

Commit 72869e7

Browse files
committed
Merge branch 'jk/is-promisor-object-keep-tree-in-use' into maint
An earlier optimization discarded a tree-object buffer that is still in use, which has been corrected. * jk/is-promisor-object-keep-tree-in-use: is_promisor_object(): fix use-after-free of tree buffer
2 parents ac8035a + 1490d7d commit 72869e7

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

packfile.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2229,7 +2229,17 @@ static int add_promisor_object(const struct object_id *oid,
22292229
void *set_)
22302230
{
22312231
struct oidset *set = set_;
2232-
struct object *obj = parse_object(the_repository, oid);
2232+
struct object *obj;
2233+
int we_parsed_object;
2234+
2235+
obj = lookup_object(the_repository, oid);
2236+
if (obj && obj->parsed) {
2237+
we_parsed_object = 0;
2238+
} else {
2239+
we_parsed_object = 1;
2240+
obj = parse_object(the_repository, oid);
2241+
}
2242+
22332243
if (!obj)
22342244
return 1;
22352245

@@ -2251,7 +2261,8 @@ static int add_promisor_object(const struct object_id *oid,
22512261
return 0;
22522262
while (tree_entry_gently(&desc, &entry))
22532263
oidset_insert(set, &entry.oid);
2254-
free_tree_buffer(tree);
2264+
if (we_parsed_object)
2265+
free_tree_buffer(tree);
22552266
} else if (obj->type == OBJ_COMMIT) {
22562267
struct commit *commit = (struct commit *) obj;
22572268
struct commit_list *parents = commit->parents;

t/t5616-partial-clone.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ test_expect_success 'do partial clone 1' '
4949
test "$(git -C pc1 config --local remote.origin.partialclonefilter)" = "blob:none"
5050
'
5151

52+
test_expect_success 'rev-list --missing=allow-promisor on partial clone' '
53+
git -C pc1 rev-list --objects --missing=allow-promisor HEAD >actual &&
54+
git -C pc1 rev-list --objects --missing=print HEAD >expect.raw &&
55+
grep -v "^?" expect.raw >expect &&
56+
test_cmp expect actual
57+
'
58+
5259
test_expect_success 'verify that .promisor file contains refs fetched' '
5360
ls pc1/.git/objects/pack/pack-*.promisor >promisorlist &&
5461
test_line_count = 1 promisorlist &&

0 commit comments

Comments
 (0)