From: Ævar Arnfjörð Bjarmason Date: Fri, 09 Jul 2021 10:13:46 GMT Subject: [PATCH v2 0/2] pack-objects: missing tests & --stdin-packs segfault fix Message-ID: In-Reply-To: When re-rolling an unrelated series[1] dealing with pack-objects.c and revision.c I discovered that we have some test blindspots, and that the newly added --stdin-packs option in v2.32.0 will segfault if fed garbage data. See http://lore.kernel.org/git/cover-0.2-00000000000-20210621T145819Z-avarab@gmail.com for the v1 of this series. This hopefully addresses Taylor's comments in https://lore.kernel.org/git/YND3h2l10PlnSNGJ@nand.local/ I didn't end up moving away from the " ## builtin/pack-objects.c ## @@ builtin/pack-objects.c: static void read_packs_list_from_stdin(void) - item->util = p; } -+ /* -+ * Arguments we got on stdin may not even be packs. Check that -+ * to avoid segfaulting later on in e.g. pack_mtime_cmp(). + /* +- * First handle all of the excluded packs, marking them as kept in-core +- * so that later calls to add_object_entry() discards any objects that +- * are also found in excluded packs. ++ * Arguments we got on stdin may not even be packs. First ++ * check that to avoid segfaulting later on in ++ * e.g. pack_mtime_cmp(), excluded packs are handled below. ++ * ++ * Since we first parsed our STDIN and then sorted the input ++ * lines the pack we error on will be whatever line happens to ++ * sort first. This is lazy, it's enough that we report one ++ * bad case here, we don't need to report the first/last one, ++ * or all of them. + */ + for_each_string_list_item(item, &include_packs) { + struct packed_git *p = item->util; @@ builtin/pack-objects.c: static void read_packs_list_from_stdin(void) + die(_("could not find pack '%s'"), item->string); + } + - /* - * First handle all of the excluded packs, marking them as kept in-core - * so that later calls to add_object_entry() discards any objects that ++ /* ++ * Then, handle all of the excluded packs, marking them as ++ * kept in-core so that later calls to add_object_entry() ++ * discards any objects that are also found in excluded packs. + */ + for_each_string_list_item(item, &exclude_packs) { + struct packed_git *p = item->util; ## t/t5300-pack-object.sh ## @@ t/t5300-pack-object.sh: test_expect_success 'pack-object err.expect <<-EOF && + fatal: could not find pack '"'"'$(git -C pack-object-stdin rev-parse two)'"'"' + EOF -+ test_must_fail git -C pack-object-stdin pack-objects stdin-with-stdin-option --stdin-packs err.actual && ++ test_must_fail git \ ++ -C pack-object-stdin \ ++ pack-objects stdin-with-stdin-option --stdin-packs \ ++ err.actual && + test_cmp err.expect err.actual +' + -- 2.32.0.636.g43e71d69cff