The offset of an object in the pack is recorded as a 4-byte integer in the index file. When reading the offset from the mmap'ed index in prepare_pack_revindex(), the address is dereferenced as a long*. This works fine as long as the long type is four bytes wide. On NetBSD/sparc64, however, a long is 8 bytes wide and so dereferencing the offset produces garbage.
Signed-off-by: Dennis Stosberg <dennis@stosberg.net>
---
I am not sure whether an int cast or an int32_t cast is more appropriate here. An int is not guaranteed to be four bytes wide, but I don't know of any modern platform where that's not the case. On the other hand int32_t is not necessarily available before C99.
Any opinions? I wonder why no one has hit this on x86_64...
pack-objects.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
026b1b2cdd5332f59e15cd8611a49ead3094d08c
Show changes to pack-objects.c +1 −1
diff --git a/pack-objects.c b/pack-objects.c index 523a1c7..29bda43 100644 --- a/pack-objects.c +++ b/pack-objects.c @@ -156,7 +156,7 @@ static void prepare_pack_revindex(struct rix->revindex = xmalloc(sizeof(unsigned long) * (num_ent + 1)); for (i = 0; i < num_ent; i++) { - long hl = *((long *)(index + 24 * i)); + long hl = *((int *)(index + 24 * i)); rix->revindex[i] = ntohl(hl); } /* This knows the pack format -- the 20-byte trailer
-- 1.3.2.gbe65