Re: [PATCH 09/20] midx: check size of object offset chunk
- From
Taylor Blau <me@ttaylorr.com>
- Date
- Oct 11, 2023, 18:31 UTC
- Message-ID
- <ZSbqFcoxUJUqC6qz@nand.local>
- In-Reply-To
- <20231009210527.GI3282181@coredump.intra.peff.net>
On Mon, Oct 09, 2023 at 05:05:27PM -0400, Jeff King wrote:
Show 16 quoted lines
> @@ -88,6 +88,19 @@ static int midx_read_oid_lookup(const unsigned char *chunk_start,
> return 0;
> }
>
> +static int midx_read_object_offsets(const unsigned char *chunk_start,
> + size_t chunk_size, void *data)
> +{
> + struct multi_pack_index *m = data;
> + m->chunk_object_offsets = chunk_start;
> +
> + if (chunk_size != st_mult(m->num_objects, MIDX_CHUNK_OFFSET_WIDTH)) {
> + error(_("multi-pack-index object offset chunk is the wrong size"));
> + return 1;
> + }
> + return 0;
> +}Makes sense, and the (elided) test below looks good, too. I think that this is another case that would benefit from having the chunk-format API take in an "expected size" and validate that the requested chunk is actually that size before assigning its address to some pointer.
Thanks, Taylor