]> git.ipfire.org Git - thirdparty/git.git/commit
packfile: detect overflow in .idx file size checks
authorJeff King <peff@peff.net>
Fri, 13 Nov 2020 05:07:19 +0000 (00:07 -0500)
committerJunio C Hamano <gitster@pobox.com>
Mon, 16 Nov 2020 21:41:35 +0000 (13:41 -0800)
commit81c4c5cf2e18d2b562639596385e49c3c48677de
tree447f0ea8161b2294122ac359d890b044c7ba4f73
parent9bb4542b8c1b91189126cf0fc42e2689fc9224c6
packfile: detect overflow in .idx file size checks

In load_idx(), we check that the .idx file is sized appropriately for
the number of objects it claims to have. We recently fixed the case
where the number of objects caused our expected size to overflow a
32-bit unsigned int, and we switched to size_t.

On a 64-bit system, this is fine; our size_t covers any expected size.
On a 32-bit system, though, it won't. The file may claim to have 2^31
objects, which will overflow even a size_t.

This doesn't hurt us at all for a well-formed idx file. A 32-bit system
would already have failed to mmap such a file, since it would be too
big. But an .idx file which _claims_ to have 2^31 objects but is
actually much smaller would fool our check.

This is a broken file, and for the most part we don't care that much
what happens. But:

  - it's a little friendlier to notice up front "woah, this file is
    broken" than it is to get nonsense results

  - later access of the data assumes that the loading function
    sanity-checked that we have at least enough bytes for the regular
    object-id table. A malformed .idx file could lead to an
    out-of-bounds read.

So let's use our overflow-checking functions to make sure that we're not
fooled by a malformed file.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
packfile.c