{"thread":{"id":"35454","subject":"[BUG] Core dump w/ bus error on bad mmap'd packfile","startedAt":"2013-12-02T22:20:08Z","lastAt":"2013-12-03T19:50:39Z","messageCount":2,"participants":["Amit Bakshi","Thomas Rast"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"231394","messageId":"CAFGOX=WsGqmgxps64mWKPJ_Anj0tNTz8nQwpyDOpfCVQ_5HXow@mail.gmail.com","threadId":"35454","inReplyTo":null,"subject":"[BUG] Core dump w/ bus error on bad mmap'd packfile","fromName":"Amit Bakshi","fromEmail":"ambakshi@gmail.com","sentAt":"2013-12-02T22:20:08Z","receivedAt":"2013-12-02T22:20:08Z","isPatch":false,"sender":{"key":"ambakshi@gmail.com","avatar":"https://avatars.githubusercontent.com/u/32329?v=4"},"body":"Hi,\n\n I was getting core dumps (bus error 7) with git 1.7.1 when doing a\ngit checkout. I tried git fsck, and same thing. I got the same with\nprecompiled rpms of 1.7.12, and with a locally compiled version of git\n1.8.5.\n\n The simplest/quickest repro I got is using git-fsck. The stacktrace\nblames SHA1_Update in verify_packfile. Upon further investigation all\nthe in/offsets/remaining seemed ok. I traced it to a 17mb packfile\nthat gets an i/o error when attempting to read it past 13mb.  It looks\nlike it's xmmap'ing the file and passing that pointer to\nSHA1_Update(). I don't know why in some paths it gives an i/o error\nand in other paths it segfaults (I added the extra debug output to\ngit-fsck).\n\n$ git fsck\nChecking pack-0ccb5ee4f60003a7ea47d6904633cce5973efa60.pack\nin: 0x7f9070507000 remain: 17345210 offset: 17345230\nBus error (core dumped)\n\ngit verify-pack correctly shows the error, without a bus error.\n\n$ git verify-pack -v pack-0ccb5ee4f60003a7ea47d6904633cce5973efa60.pack\nfatal: read error on input: Input/output error\npack-0ccb5ee4f60003a7ea47d6904633cce5973efa60.pack: bad\n\nNot sure what the right solution is without impacting perf, but it\ntook me a while to track down and having an error message indicating\nthe bad file would've been a great help.\n\nAmit\n"},{"id":"231461","messageId":"87vbz5n27k.fsf@linux-1gf2.Speedport_W723_V_Typ_A_1_00_098","threadId":"35454","inReplyTo":"CAFGOX=WsGqmgxps64mWKPJ_Anj0tNTz8nQwpyDOpfCVQ_5HXow@mail.gmail.com","subject":"Re: [BUG] Core dump w/ bus error on bad mmap'd packfile","fromName":"Thomas Rast","fromEmail":"tr@thomasrast.ch","sentAt":"2013-12-03T19:50:39Z","receivedAt":"2013-12-03T19:50:39Z","isPatch":false,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Amit Bakshi <ambakshi@gmail.com> writes:\n\n>  I was getting core dumps (bus error 7) with git 1.7.1 when doing a\n> git checkout. I tried git fsck, and same thing. I got the same with\n> precompiled rpms of 1.7.12, and with a locally compiled version of git\n> 1.8.5.\n[...]\n> $ git fsck\n> Checking pack-0ccb5ee4f60003a7ea47d6904633cce5973efa60.pack\n> in: 0x7f9070507000 remain: 17345210 offset: 17345230\n> Bus error (core dumped)\n>\n> git verify-pack correctly shows the error, without a bus error.\n>\n> $ git verify-pack -v pack-0ccb5ee4f60003a7ea47d6904633cce5973efa60.pack\n> fatal: read error on input: Input/output error\n> pack-0ccb5ee4f60003a7ea47d6904633cce5973efa60.pack: bad\n\nmmap()ing a file and attempting to read from parts that the kernel can\nthen not page in (in your case because it couldn't read the file) are\nexpected to give a SIGBUS, so there is no bug here.  The different\nbehavior comes from some commands using mmap() and some using read() to\naccess the packs.\n\nPerhaps we could try to map the faulting address back to the file it\ncame from, though.  The siginfo_t for a SIGBUS contains information\nabout the faulting address, so for the case of packs we could walk the\n'struct packed_git' list and see which open window the address belongs\nto.  I need to think about the implications of doing that in a signal\nhandler, though.\n\n-- \nThomas Rast\ntr@thomasrast.ch\n"}]}