]> git.ipfire.org Git - thirdparty/git.git/commit
midx: stop ignoring malformed oid fanout chunk
authorJeff King <peff@peff.net>
Mon, 9 Oct 2023 20:59:19 +0000 (16:59 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 9 Oct 2023 22:55:00 +0000 (15:55 -0700)
commite3c9600397bde3dcd2f628ff1eec098f79f79b67
tree253254e9bc468671343cded17d4fae98deb52092
parent86b008ee61ccf800f613d7de382bd9e3b6bbaa6f
midx: stop ignoring malformed oid fanout chunk

When we load the oid-fanout chunk, our callback checks that its size is
reasonable and returns an error if not. However, the caller only checks
our return value against CHUNK_NOT_FOUND, so we end up ignoring the
error completely! Using a too-small fanout table means we end up
accessing random memory for the fanout and segfault.

We can fix this by checking for any non-zero return value, rather than
just CHUNK_NOT_FOUND, and adjusting our error message to cover both
cases. We could handle each error code individually, but there's not
much point for such a rare case. The extra message produced in the
callback makes it clear what is going on.

The same pattern is used in the adjacent code. Those cases are actually
OK for now because they do not use a custom callback, so the only error
they can get is CHUNK_NOT_FOUND. But let's convert them, as this is an
accident waiting to happen (especially as we convert some of them away
from pair_chunk). The error messages are more verbose, but it should be
rare for a user to see these anyway.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
midx.c
t/t5319-multi-pack-index.sh