fsck: correctly compute checksums on idx files larger than 4GB
authorJeff King <redacted>
Fri, 13 Nov 2020 05:07:14 +0000 (00:07 -0500)
committerJunio C Hamano <redacted>
Mon, 16 Nov 2020 21:41:35 +0000 (13:41 -0800)
commit33bbc59fed34848215f8ce1ef71ff26b821ccd12
tree911d5f9e0679376ee8ddf3955b598a506a7a5154
parenta9bc372ef8210e60d924ec6c0b46624c6d0a4033
fsck: correctly compute checksums on idx files larger than 4GB

When checking the trailing checksum hash of a .idx file, we pass the
whole buffer (minus the trailing hash) into a single call to
the_hash_algo->update_fn(). But we cast it to an "unsigned int". This
comes from c4001d92be (Use off_t when we really mean a file offset.,
2007-03-06). That commit started storing the index_size variable as an
off_t, but our mozilla-sha1 implementation from the time was limited to
a smaller size. Presumably the cast was a way of annotating that we
expected .idx files to be small, and so we didn't need to loop (as we do
for arbitrarily-large .pack files). Though as an aside it was still
wrong, because the mozilla function actually took a signed int.

These days our hash-update functions are defined to take a size_t, so we
can pass the whole buffer in directly. The cast is actually causing a
buggy truncation!

While we're here, though, let's drop the confusing off_t variable in the
first place. We're getting the size not from the filesystem anyway, but
from p->index_size, which is a size_t. In fact, we can make the code a
bit more readable by dropping our local variable duplicating
p->index_size, and instead have one that stores the size of the actual
index data, minus the trailing hash.

Signed-off-by: Jeff King <redacted>
Signed-off-by: Junio C Hamano <redacted>
pack-check.c
git clone https://git.99rst.org/PROJECT