git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] pack-bitmap.c: avoid uninitialized `pack_int_id` during reuse

From
Taylor Blau <me@ttaylorr.com>
Date
Jun 10, 2024, 14:57 UTC
Message-ID
<ZmcUclCErqwyad9D@nand.local>
In-Reply-To
<ZmaVYnmgyAr0vapK@tanuki>
On Mon, Jun 10, 2024 at 07:55:46AM +0200, Patrick Steinhardt wrote:
Show 10 quoted lines
> On Sun, Jun 09, 2024 at 11:27:35AM -0400, Taylor Blau wrote:
> > In 795006fff4 (pack-bitmap: gracefully handle missing BTMP chunks,
> > 2024-04-15), we refactored the reuse_partial_packfile_from_bitmap()
> > function and stopped assigning the pack_int_id field when reusing only
> > the MIDX's preferred pack. This results in an uninitialized read down in
> > try_partial_reuse() like so:
>
> I feel like I'm blind, but I cannot see how the patch changed what we do
> with `pack_int_id`. It's not mentioned a single time in the diff, so how
> did it have the effect of not setting it anymore?

It's because prior to 795006fff4, we handled reusing a single pack from a MIDX differently than in the post-image of that commit. Prior to 795006fff4, the loop looked like:

    if (bitmap_is_midx(bitmap_git)) {
            for (i = 0; i < bitmap_git->midx->num_packs; i++) {
                    struct bitmapped_pack pack;
                    if (nth_bitmapped_pack(r, bitmap_git->midx, &pack, i) < 0) {
                          /* ... */
                          return;
                    }
                    if (!pack.bitmap_nr)
                          continue;
                    if (!multi_pack_reuse && pack.bitmap_pos)
                          continue;
                    ALLOC_GROW(packs, packs_nr + 1, packs_alloc);
                    memcpy(&packs[packs_nr++], &pack, sizeof(pack));
            }
    }

Since nth_bitmapped_pack() fills out the pack_int_id field, we got it automatically since we just memcpy()'d the result of nth_bitmapped_pack() into our array.

In the single pack bitmap case, we don't need to initialize the pack_int_id field because we never read it, hence the lack of MSan failures in that mode.

But since 795006fff4 combined these two single pack cases (that is, single-pack bitmaps, and reusing only a single pack out of a MIDX bitmap) into one, 795006fff4 neglected to initialize the pack_int_id field, causing this issue.

Thanks, Taylor

Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 3 of 15 in “pack-bitmap.c: avoid uninitialized `pack_int_id` during reuse”
  1. pack-bitmap.c: avoid uninitialized `pack_int_id` during reuseTaylor Blau, Jun 9, 2024
  2. Patrick SteinhardtJun 10, 2024
  3. Taylor BlauJun 10, 2024
  4. Patrick SteinhardtJun 11, 2024
  5. 0/3 midx: various brown paper bag fixesTaylor Blau, Jun 10, 2024
  6. 1/3 midx-write.c: do not read existing MIDX with `packs_to_include`Taylor Blau, Jun 10, 2024
  7. 2/3 pack-bitmap.c: avoid uninitialized `pack_int_id` during reuseTaylor Blau, Jun 10, 2024
  8. Jeff KingJun 11, 2024
  9. Junio C HamanoJun 11, 2024
  10. 3/3 pack-revindex.c: guard against out-of-bounds pack lookupsTaylor Blau, Jun 10, 2024
  11. 0/3 midx: various brown paper bag fixesTaylor Blau, Jun 11, 2024
  12. 1/3 midx-write.c: do not read existing MIDX with `packs_to_include`Taylor Blau, Jun 11, 2024
  13. 2/3 pack-bitmap.c: avoid uninitialized `pack_int_id` during reuseTaylor Blau, Jun 11, 2024
  14. 3/3 pack-revindex.c: guard against out-of-bounds pack lookupsTaylor Blau, Jun 11, 2024
  15. Taylor BlauJun 11, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.