# segfault in diff-delta.c on mac os x (commit 8433669)

4 messages from 2007-07-21 to 2007-07-22. Participants: Steffen Prohaska, Brian Gernhardt.
Thread: https://gitlist.dev/t/9127

## Steffen Prohaska, 2007-07-21 15:15

Subject: segfault in diff-delta.c on mac os x (commit 8433669)
Message-ID: <C10CCDA5-6D65-445E-92F3-2D3E4DCA4F8B@zib.de>
URL: https://gitlist.dev/e/C10CCDA5-6D65-445E-92F3-2D3E4DCA4F8B%40zib.de

```
843366961cf14aad6490fbeb30f7b98f37f8833a may cause segfaults on
Mac OS X. See backtrace below. I only observed the segfault with
-O2 builds.

I was not yet able to understand the reason causing the segfault.
The situation is kind of strange. The for loop in line 302 shouldn't
allow entry == 0 to ever happen. But maybe some more intricate
corruption is taking place.

Unfortunately I'm no longer able to reproduce the exact call stack
because I wasn't aware of the details of when pruning takes place;
and the repository changed in such a way that the segfault no
longer happens.

However, I experienced suspicious behaviour on other repositories
during packing as well. I can probably create similar call stacks
if needed.

For now, I reverted 843366961cf14aad6490fbeb30f7b98f37f8833a for me.

	Steffen


gcc --version
i686-apple-darwin8-gcc-4.0.1 (GCC) 4.0.1 (Apple Computer, Inc. build  
5250)
Copyright (C) 2005 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There  
is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR  
PURPOSE.


Counting objects: 7530
Done counting 56361 objects.
Deltifying 56361 objects...
   69% (38890/56361) done

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x00000000
0x00048526 in create_delta (index=0x35d5000, trg_buf=0x35a0000,  
trg_size=214109, delta_size=0xbfffe83c, max_size=104893) at diff- 
delta.c:303
303                                     const unsigned char *ref =  
entry->ptr;
(gdb) bt
#0  0x00048526 in create_delta (index=0x35d5000, trg_buf=0x35a0000,  
trg_size=214109, delta_size=0xbfffe83c, max_size=104893) at diff- 
delta.c:303
#1  0x0002beb7 in prepare_pack (window=10, depth=50) at builtin-pack- 
objects.c:1293
#2  0x0002cd6e in cmd_pack_objects (argc=16, argv=0xbfffef78,  
prefix=0x0) at builtin-pack-objects.c:1709
#3  0x000020c9 in handle_internal_command (argc=16, argv=0xbfffef78,  
envp=0x84) at git.c:324
#4  0x00002669 in main (argc=16, argv=0xbfffef78, envp=0xbfffefbc) at  
git.c:393
(gdb) l
298                             struct index_entry *entry;
299                             val ^= U[data[-RABIN_WINDOW]];
300                             val = ((val << 8) | *data) ^ T[val >>  
RABIN_SHIFT];
301                             i = val & index->hash_mask;
302                             for (entry = index->hash[i]; entry;  
entry = entry->next) {
303                                     const unsigned char *ref =  
entry->ptr;
304                                     const unsigned char *src = data;
305                                     unsigned int ref_size =  
ref_top - ref;
306                                     if (entry->val != val)
307                                             continue;
(gdb) p entry
$1 = (struct index_entry *) 0x0

```

## Brian Gernhardt, 2007-07-22 03:35

Subject: Re: segfault in diff-delta.c on mac os x (commit 8433669)
Message-ID: <233B9D70-9D91-4527-9801-7E2463ABDDAA@silverinsanity.com>
URL: https://gitlist.dev/e/233B9D70-9D91-4527-9801-7E2463ABDDAA%40silverinsanity.com
In-Reply-To: <C10CCDA5-6D65-445E-92F3-2D3E4DCA4F8B@zib.de>

```

On Jul 21, 2007, at 11:15 AM, Steffen Prohaska wrote:

> 843366961cf14aad6490fbeb30f7b98f37f8833a may cause segfaults on
> Mac OS X. See backtrace below. I only observed the segfault with
> -O2 builds.

I have been using git on my OS X box for quite a while, and that  
commit appears to be nearly two months old.  I have yet to see any  
packing errors in any of my repositories.  (This is with -O2, which  
appears to be the default.)

My gcc reports itself as build 5367 instead of 5250.  Perhaps there  
is a compiler error in an older copy of the DevTools?

Also, did this segfault occur with any publicly available repo or is  
it your own work?

~~ Brian

```

## Steffen Prohaska, 2007-07-22 08:49

Subject: Re: segfault in diff-delta.c on mac os x (commit 8433669)
Message-ID: <6A487E9A-27E5-4212-A7C9-EBB6528791FE@zib.de>
URL: https://gitlist.dev/e/6A487E9A-27E5-4212-A7C9-EBB6528791FE%40zib.de
In-Reply-To: <233B9D70-9D91-4527-9801-7E2463ABDDAA@silverinsanity.com>

```

On Jul 22, 2007, at 5:35 AM, Brian Gernhardt wrote:

>
> On Jul 21, 2007, at 11:15 AM, Steffen Prohaska wrote:
>
>> 843366961cf14aad6490fbeb30f7b98f37f8833a may cause segfaults on
>> Mac OS X. See backtrace below. I only observed the segfault with
>> -O2 builds.
>
> I have been using git on my OS X box for quite a while, and that  
> commit appears to be nearly two months old.  I have yet to see any  
> packing errors in any of my repositories.  (This is with -O2, which  
> appears to be the default.)
>
> My gcc reports itself as build 5367 instead of 5250.  Perhaps there  
> is a compiler error in an older copy of the DevTools?

This seems to be the case. I upgraded the compiler and
tried again. The segfault didn't happen again. Note, this
was not exactly the same situation as before because the
git repository used for testing changed a bit since the
first segfault.

I'll do some more repacking over the day and will report
my observations.


> Also, did this segfault occur with any publicly available repo or  
> is it your own work?

It occurred on repacking a clone of
git://git.kernel.org/pub/scm/git/git.git.


	Steffen

```

## Steffen Prohaska, 2007-07-22 12:59

Subject: Re: segfault in diff-delta.c on mac os x (commit 8433669)
Message-ID: <B19AC964-3398-46AF-934B-BB2F06688F7B@zib.de>
URL: https://gitlist.dev/e/B19AC964-3398-46AF-934B-BB2F06688F7B%40zib.de
In-Reply-To: <6A487E9A-27E5-4212-A7C9-EBB6528791FE@zib.de>

```

On Jul 22, 2007, at 10:49 AM, Steffen Prohaska wrote:

>
> On Jul 22, 2007, at 5:35 AM, Brian Gernhardt wrote:
>
>>
>> On Jul 21, 2007, at 11:15 AM, Steffen Prohaska wrote:
>>
>>> 843366961cf14aad6490fbeb30f7b98f37f8833a may cause segfaults on
>>> Mac OS X. See backtrace below. I only observed the segfault with
>>> -O2 builds.
>>
>> I have been using git on my OS X box for quite a while, and that  
>> commit appears to be nearly two months old.  I have yet to see any  
>> packing errors in any of my repositories.  (This is with -O2,  
>> which appears to be the default.)
>>
>> My gcc reports itself as build 5367 instead of 5250.  Perhaps  
>> there is a compiler error in an older copy of the DevTools?
>
> This seems to be the case. I upgraded the compiler and
> tried again. The segfault didn't happen again. Note, this
> was not exactly the same situation as before because the
> git repository used for testing changed a bit since the
> first segfault.
>
> I'll do some more repacking over the day and will report
> my observations.

I did a lot more testing and am pretty convinced now that
the problem is not present with the newer compiler. Using
build 5367 of gcc seems to creating a working git executable
while build 5250 creates a broken one.

	Steffen

```
