diff options
author | Jeff King <peff@peff.net> | 2023-10-09 23:05:47 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-10-10 00:55:01 +0200 |
commit | ee6a7924124b2a9030da55c94a27829e410b3b64 (patch) | |
tree | d8833327e28205cad1b3748d9776c2597f47dd2d /commit-graph.h | |
parent | commit-graph: check size of generations chunk (diff) | |
download | git-ee6a7924124b2a9030da55c94a27829e410b3b64.tar.xz git-ee6a7924124b2a9030da55c94a27829e410b3b64.zip |
commit-graph: bounds-check generation overflow chunk
If the generation entry in a commit-graph doesn't fit, we instead insert
an offset into a generation overflow chunk. But since we don't record
the size of the chunk, we may read outside the chunk if the offset we
find on disk is malicious or corrupted.
We can't check the size of the chunk up-front; it will vary based on how
many entries need overflow. So instead, we'll do a bounds-check before
accessing the chunk memory. Unfortunately there is no error-return from
this function, so we'll just have to die(), which is what it does for
other forms of corruption.
As with other cases, we can drop the st_mult() call, since we know our
bounds-checked value will fit within a size_t.
Before this patch, the test here actually "works" because we read
garbage data from the next chunk. And since that garbage data happens
not to provide a generation number which changes the output, it appears
to work. We could construct a case that actually segfaults or produces
wrong output, but it would be a bit tricky. For our purposes its
sufficient to check that we've detected the bounds error.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'commit-graph.h')
-rw-r--r-- | commit-graph.h | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/commit-graph.h b/commit-graph.h index e4248ea05d..b373f15802 100644 --- a/commit-graph.h +++ b/commit-graph.h @@ -94,6 +94,7 @@ struct commit_graph { const unsigned char *chunk_commit_data; const unsigned char *chunk_generation_data; const unsigned char *chunk_generation_data_overflow; + size_t chunk_generation_data_overflow_size; const unsigned char *chunk_extra_edges; size_t chunk_extra_edges_size; const unsigned char *chunk_base_graphs; |