# [PATCH] pack-bitmap: Don't perform unaligned memory access

3 messages from 2017-06-26 to 2017-06-27. Participants: James Clarke, Junio C Hamano, Jonathan Nieder.
Thread: https://gitlist.dev/t/46262

## James Clarke, 2017-06-26 15:16

Subject: [PATCH] pack-bitmap: Don't perform unaligned memory access
Message-ID: <20170626151612.64019-1-jrtc27@jrtc27.com>
URL: https://gitlist.dev/e/20170626151612.64019-1-jrtc27%40jrtc27.com

```
The preceding bitmap entries have a 1-byte XOR-offset and 1-byte flags,
so their size is not a multiple of 4. Thus the name-hash cache is only
guaranteed to be 2-byte aligned and so we must use get_be32 rather than
indexing the array directly.

Signed-off-by: James Clarke <jrtc27@jrtc27.com>
---

This was noticed thanks to the recent tests added to t5310-pack-bitmaps.sh,
which were crashing with SIGBUS on Debian sparc64. All tests (excluding those
marked with known breakage) now pass again.

 pack-bitmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pack-bitmap.c b/pack-bitmap.c
index a3ac3dccd..327634cd7 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -627,7 +627,7 @@ static void show_objects_for_type(
 			sha1 = nth_packed_object_sha1(bitmap_git.pack, entry->nr);

 			if (bitmap_git.hashes)
-				hash = ntohl(bitmap_git.hashes[entry->nr]);
+				hash = get_be32(bitmap_git.hashes + entry->nr);

 			show_reach(sha1, object_type, 0, hash, bitmap_git.pack, entry->offset);
 		}
--
2.13.2


```

## Junio C Hamano, 2017-06-26 19:30

Subject: Re: [PATCH] pack-bitmap: Don't perform unaligned memory access
Message-ID: <xmqqr2y64kdj.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqr2y64kdj.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <20170626151612.64019-1-jrtc27@jrtc27.com>

```
James Clarke <jrtc27@jrtc27.com> writes:

> The preceding bitmap entries have a 1-byte XOR-offset and 1-byte flags,
> so their size is not a multiple of 4. Thus the name-hash cache is only
> guaranteed to be 2-byte aligned and so we must use get_be32 rather than
> indexing the array directly.
>
> Signed-off-by: James Clarke <jrtc27@jrtc27.com>
> ---
>
> This was noticed thanks to the recent tests added to t5310-pack-bitmaps.sh,
> which were crashing with SIGBUS on Debian sparc64. All tests (excluding those
> marked with known breakage) now pass again.

Thanks.

>
>  pack-bitmap.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/pack-bitmap.c b/pack-bitmap.c
> index a3ac3dccd..327634cd7 100644
> --- a/pack-bitmap.c
> +++ b/pack-bitmap.c
> @@ -627,7 +627,7 @@ static void show_objects_for_type(
>  			sha1 = nth_packed_object_sha1(bitmap_git.pack, entry->nr);
>
>  			if (bitmap_git.hashes)
> -				hash = ntohl(bitmap_git.hashes[entry->nr]);
> +				hash = get_be32(bitmap_git.hashes + entry->nr);
>
>  			show_reach(sha1, object_type, 0, hash, bitmap_git.pack, entry->offset);
>  		}
> --
> 2.13.2

```

## Jonathan Nieder, 2017-06-27 00:06

Subject: Re: [PATCH] pack-bitmap: Don't perform unaligned memory access
Message-ID: <20170627000600.GD161648@aiede.mtv.corp.google.com>
URL: https://gitlist.dev/e/20170627000600.GD161648%40aiede.mtv.corp.google.com
In-Reply-To: <20170626151612.64019-1-jrtc27@jrtc27.com>

```
James Clarke wrote:

> The preceding bitmap entries have a 1-byte XOR-offset and 1-byte flags,
> so their size is not a multiple of 4. Thus the name-hash cache is only
> guaranteed to be 2-byte aligned and so we must use get_be32 rather than
> indexing the array directly.
>
> Signed-off-by: James Clarke <jrtc27@jrtc27.com>
> ---
>  pack-bitmap.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

Failing build log:
https://buildd.debian.org/status/fetch.php?pkg=git&arch=sparc64&ver=1%3A2.13.2-2&stamp=1498520310&raw=0

Thanks for tracking down and fixing it.

```
