# [BUG] Core dump w/ bus error on bad mmap'd packfile

2 messages from 2013-12-02 to 2013-12-03. Participants: Amit Bakshi, Thomas Rast.
Thread: https://gitlist.dev/t/35454

## Amit Bakshi, 2013-12-02 22:20

Subject: [BUG] Core dump w/ bus error on bad mmap'd packfile
Message-ID: <CAFGOX=WsGqmgxps64mWKPJ_Anj0tNTz8nQwpyDOpfCVQ_5HXow@mail.gmail.com>
URL: https://gitlist.dev/e/CAFGOX%3DWsGqmgxps64mWKPJ_Anj0tNTz8nQwpyDOpfCVQ_5HXow%40mail.gmail.com

```
Hi,

 I was getting core dumps (bus error 7) with git 1.7.1 when doing a
git checkout. I tried git fsck, and same thing. I got the same with
precompiled rpms of 1.7.12, and with a locally compiled version of git
1.8.5.

 The simplest/quickest repro I got is using git-fsck. The stacktrace
blames SHA1_Update in verify_packfile. Upon further investigation all
the in/offsets/remaining seemed ok. I traced it to a 17mb packfile
that gets an i/o error when attempting to read it past 13mb.  It looks
like it's xmmap'ing the file and passing that pointer to
SHA1_Update(). I don't know why in some paths it gives an i/o error
and in other paths it segfaults (I added the extra debug output to
git-fsck).

$ git fsck
Checking pack-0ccb5ee4f60003a7ea47d6904633cce5973efa60.pack
in: 0x7f9070507000 remain: 17345210 offset: 17345230
Bus error (core dumped)

git verify-pack correctly shows the error, without a bus error.

$ git verify-pack -v pack-0ccb5ee4f60003a7ea47d6904633cce5973efa60.pack
fatal: read error on input: Input/output error
pack-0ccb5ee4f60003a7ea47d6904633cce5973efa60.pack: bad

Not sure what the right solution is without impacting perf, but it
took me a while to track down and having an error message indicating
the bad file would've been a great help.

Amit

```

## Thomas Rast, 2013-12-03 19:50

Subject: Re: [BUG] Core dump w/ bus error on bad mmap'd packfile
Message-ID: <87vbz5n27k.fsf@linux-1gf2.Speedport_W723_V_Typ_A_1_00_098>
URL: https://gitlist.dev/e/87vbz5n27k.fsf%40linux-1gf2.Speedport_W723_V_Typ_A_1_00_098
In-Reply-To: <CAFGOX=WsGqmgxps64mWKPJ_Anj0tNTz8nQwpyDOpfCVQ_5HXow@mail.gmail.com>

```
Amit Bakshi <ambakshi@gmail.com> writes:

>  I was getting core dumps (bus error 7) with git 1.7.1 when doing a
> git checkout. I tried git fsck, and same thing. I got the same with
> precompiled rpms of 1.7.12, and with a locally compiled version of git
> 1.8.5.
[...]
> $ git fsck
> Checking pack-0ccb5ee4f60003a7ea47d6904633cce5973efa60.pack
> in: 0x7f9070507000 remain: 17345210 offset: 17345230
> Bus error (core dumped)
>
> git verify-pack correctly shows the error, without a bus error.
>
> $ git verify-pack -v pack-0ccb5ee4f60003a7ea47d6904633cce5973efa60.pack
> fatal: read error on input: Input/output error
> pack-0ccb5ee4f60003a7ea47d6904633cce5973efa60.pack: bad

mmap()ing a file and attempting to read from parts that the kernel can
then not page in (in your case because it couldn't read the file) are
expected to give a SIGBUS, so there is no bug here.  The different
behavior comes from some commands using mmap() and some using read() to
access the packs.

Perhaps we could try to map the faulting address back to the file it
came from, though.  The siginfo_t for a SIGBUS contains information
about the faulting address, so for the case of packs we could walk the
'struct packed_git' list and see which open window the address belongs
to.  I need to think about the implications of doing that in a signal
handler, though.

-- 
Thomas Rast
tr@thomasrast.ch

```
