Re: [PATCH 1/7] chunk-format: introduce `pair_chunk_expect()` helper
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Nov 10, 2023, 23:38 UTC
- Message-ID
- <xmqqa5rluqk1.fsf@gitster.g>
- In-Reply-To
- <ZU5Z/Z4PcdNP5U1r@nand.local>
Taylor Blau <me@ttaylorr.com> writes:
Show 7 quoted lines
> But I don't think we enjoy the same benefits in the MIDX scenario. In > this case, the num_objects field is just: > > m->num_objects = ntohl(m->chunk_oid_fanout[255]) > > so I don't think we can make the same guarantees about what is and isn't > save to compute under size_t arithmetic.
So ..., from the correctness's point of view, if we do not mind st_mult() dying, the "multiply-and-compare" should give us much more robust results. If we do mind st_mult() dying, we could pair the "truncating-division-and-compare" you wrote with "ensure that chunk size is a multiple of record size" to achieve the same, I would think. I.e.,
if (chunk_size % pcd->record_size || chunk_size / pcd->record_size != pcd->record_nr) return -1;
or something like that.