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

Re: [PATCH 2/2] pack-bitmap.c: ensure pseudo-merge offset reads are bounded

From
Taylor Blau <me@ttaylorr.com>
Date
Jun 6, 2024, 22:25 UTC
Message-ID
<ZmI3RYSsx6VRHdc9@nand.local>
In-Reply-To
<xmqqfrtpluws.fsf@gitster.g>
On Thu, Jun 06, 2024 at 12:42:59PM -0700, Junio C Hamano wrote:
> Can table_size at this point be smaller than 24, which will allow
> (table_size - 24) to be a huge number that st_mult() will
> comfortably fit?

It could be smaller than 24, but I think we're at the point of diminishing returns here. The table_size field is read from the .bitmap file itself, and we do some light bounds checking here:

    table_size = get_be64(index_end - 8);
    if (table_size > index_end - index->map - header_size)
        return error(_(...));

We could add another check to ensure that table_size is at least 24, but I'm less concerned here for a couple of reasons:

  - Since we're reading off of the index_end, we know that all of our
    reads are within the .bitmap itself, so we're not reading outside of
    the memory-mapped region.
  - Checking that index->pseudo_merges.nr is a reasonable size also
    bounds reads, but more importantly IMHO prevents a large heap
    allocation via the CALLOC_ARRAY() below.

So I think we could check the table_size value, but I'm not sure we'd gain very much by doing so.

Thanks, Taylor

Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 12 in “Documentation/technical/bitmap-format.txt: add missing position table”
  1. 1/2 Documentation/technical/bitmap-format.txt: add missing position tableTaylor Blau, Jun 6, 2024
  2. 2/2 pack-bitmap.c: ensure pseudo-merge offset reads are boundedTaylor Blau, Jun 6, 2024
  3. Junio C HamanoJun 6, 2024
  4. Taylor BlauJun 6, 2024
  5. Junio C HamanoJun 6, 2024
  6. Taylor BlauJun 6, 2024
  7. Junio C HamanoJun 14, 2024
  8. 0/2 pseudo-merge: various small fixesTaylor Blau, Jun 14, 2024
  9. 1/2 Documentation/technical/bitmap-format.txt: add missing position tableTaylor Blau, Jun 14, 2024
  10. 2/2 pack-bitmap.c: ensure pseudo-merge offset reads are boundedTaylor Blau, Jun 14, 2024
  11. Elijah NewrenJun 14, 2024
  12. Junio C HamanoJun 14, 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.