]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'jk/is-promisor-object-keep-tree-in-use' into maint
authorJunio C Hamano <gitster@pobox.com>
Tue, 13 Sep 2022 19:21:07 +0000 (12:21 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 13 Sep 2022 19:21:07 +0000 (12:21 -0700)
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

packfile.c
t/t5616-partial-clone.sh

index e5b1d0ed7670a72a664ea72dbd5d37e49f15b46e..75c254e0e0cbdb00cb7f41056060d3c7e91021aa 100644 (file)
@@ -2229,7 +2229,17 @@ static int add_promisor_object(const struct object_id *oid,
                               void *set_)
 {
        struct oidset *set = set_;
-       struct object *obj = parse_object(the_repository, oid);
+       struct object *obj;
+       int we_parsed_object;
+
+       obj = lookup_object(the_repository, oid);
+       if (obj && obj->parsed) {
+               we_parsed_object = 0;
+       } else {
+               we_parsed_object = 1;
+               obj = parse_object(the_repository, oid);
+       }
+
        if (!obj)
                return 1;
 
@@ -2251,7 +2261,8 @@ static int add_promisor_object(const struct object_id *oid,
                        return 0;
                while (tree_entry_gently(&desc, &entry))
                        oidset_insert(set, &entry.oid);
-               free_tree_buffer(tree);
+               if (we_parsed_object)
+                       free_tree_buffer(tree);
        } else if (obj->type == OBJ_COMMIT) {
                struct commit *commit = (struct commit *) obj;
                struct commit_list *parents = commit->parents;
index 4a3778d04a82df6322048e34864578860b96f859..9aeacc2f6a5267cfdf8a05f2c924f4ecd04fe319 100755 (executable)
@@ -49,6 +49,13 @@ test_expect_success 'do partial clone 1' '
        test "$(git -C pc1 config --local remote.origin.partialclonefilter)" = "blob:none"
 '
 
+test_expect_success 'rev-list --missing=allow-promisor on partial clone' '
+       git -C pc1 rev-list --objects --missing=allow-promisor HEAD >actual &&
+       git -C pc1 rev-list --objects --missing=print HEAD >expect.raw &&
+       grep -v "^?" expect.raw >expect &&
+       test_cmp expect actual
+'
+
 test_expect_success 'verify that .promisor file contains refs fetched' '
        ls pc1/.git/objects/pack/pack-*.promisor >promisorlist &&
        test_line_count = 1 promisorlist &&