[PATCH 02/20] packfile.c: prevent overflow in `load_idx()`
- From
Taylor Blau <me@ttaylorr.com>
- Date
- Jul 12, 2023, 23:37 UTC
- Message-ID
- <d6902cd9e7f7f2a6b8044c8fb782a28c23e15600.1689205042.git.me@ttaylorr.com>
- In-Reply-To
- <cover.1689205042.git.me@ttaylorr.com>
Prevent an overflow when locating a pack's CRC offset when the number of packed items is greater than 2^32-1/hashsz by guarding the computation with an `st_mult()`.
Signed-off-by: Taylor Blau <me@ttaylorr.com> --- packfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/packfile.c b/packfile.c index 89220f0e03..70acf1694b 100644 --- a/packfile.c +++ b/packfile.c @@ -186,7 +186,7 @@ int load_idx(const char *path, const unsigned int hashsz, void *idx_map, */ (sizeof(off_t) <= 4)) return error("pack too large for current definition of off_t in %s", path); - p->crc_offset = 8 + 4 * 256 + nr * hashsz; + p->crc_offset = st_add(8 + 4 * 256, st_mult(nr, hashsz)); } p->index_version = version;
-- 2.41.0.347.g7b976b8871f