aboutsummaryrefslogtreecommitdiffstats
path: root/chunk-format.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2023-10-23 13:56:36 -0700
committerJunio C Hamano <gitster@pobox.com>2023-10-23 13:56:36 -0700
commitf32af12ceec1c19d8a8a7874523d3a7ceef6eebf (patch)
tree9078d206b9956c89334901fd04f8a884f01379d6 /chunk-format.c
parentThe twentieth batch (diff)
parentt5319: make corrupted large-offset test more robust (diff)
downloadgit-f32af12ceec1c19d8a8a7874523d3a7ceef6eebf.tar.gz
git-f32af12ceec1c19d8a8a7874523d3a7ceef6eebf.zip
Merge branch 'jk/chunk-bounds'
The codepaths that read "chunk" formatted files have been corrected to pay attention to the chunk size and notice broken files. * jk/chunk-bounds: (21 commits) t5319: make corrupted large-offset test more robust chunk-format: drop pair_chunk_unsafe() commit-graph: detect out-of-order BIDX offsets commit-graph: check bounds when accessing BIDX chunk commit-graph: check bounds when accessing BDAT chunk commit-graph: bounds-check generation overflow chunk commit-graph: check size of generations chunk commit-graph: bounds-check base graphs chunk commit-graph: detect out-of-bounds extra-edges pointers commit-graph: check size of commit data chunk midx: check size of revindex chunk midx: bounds-check large offset chunk midx: check size of object offset chunk midx: enforce chunk alignment on reading midx: check size of pack names chunk commit-graph: check consistency of fanout table midx: check size of oid lookup chunk commit-graph: check size of oid fanout chunk midx: stop ignoring malformed oid fanout chunk t: add library for munging chunk-format files ...
Diffstat (limited to 'chunk-format.c')
-rw-r--r--chunk-format.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/chunk-format.c b/chunk-format.c
index 140dfa0dcc..cdc7f39b70 100644
--- a/chunk-format.c
+++ b/chunk-format.c
@@ -102,7 +102,8 @@ int read_table_of_contents(struct chunkfile *cf,
const unsigned char *mfile,
size_t mfile_size,
uint64_t toc_offset,
- int toc_length)
+ int toc_length,
+ unsigned expected_alignment)
{
int i;
uint32_t chunk_id;
@@ -120,6 +121,11 @@ int read_table_of_contents(struct chunkfile *cf,
error(_("terminating chunk id appears earlier than expected"));
return 1;
}
+ if (chunk_offset % expected_alignment != 0) {
+ error(_("chunk id %"PRIx32" not %d-byte aligned"),
+ chunk_id, expected_alignment);
+ return 1;
+ }
table_of_contents += CHUNK_TOC_ENTRY_SIZE;
next_chunk_offset = get_be64(table_of_contents + 4);
@@ -154,20 +160,28 @@ int read_table_of_contents(struct chunkfile *cf,
return 0;
}
+struct pair_chunk_data {
+ const unsigned char **p;
+ size_t *size;
+};
+
static int pair_chunk_fn(const unsigned char *chunk_start,
size_t chunk_size,
void *data)
{
- const unsigned char **p = data;
- *p = chunk_start;
+ struct pair_chunk_data *pcd = data;
+ *pcd->p = chunk_start;
+ *pcd->size = chunk_size;
return 0;
}
int pair_chunk(struct chunkfile *cf,
uint32_t chunk_id,
- const unsigned char **p)
+ const unsigned char **p,
+ size_t *size)
{
- return read_chunk(cf, chunk_id, pair_chunk_fn, p);
+ struct pair_chunk_data pcd = { .p = p, .size = size };
+ return read_chunk(cf, chunk_id, pair_chunk_fn, &pcd);
}
int read_chunk(struct chunkfile *cf,