# Potential bug in pack-objects.c

3 messages from 2019-01-21 to 2019-01-22. Participants: Alex Netkachov, Jeff King.
Thread: https://gitlist.dev/t/50278

## Alex Netkachov, 2019-01-21 22:10

Subject: Potential bug in pack-objects.c
Message-ID: <CAGAu0HVeQFA_O8_hsZbzRi9X35fF3DAeUaSd993JF=NTwaZP1Q@mail.gmail.com>
URL: https://gitlist.dev/e/CAGAu0HVeQFA_O8_hsZbzRi9X35fF3DAeUaSd993JF%3DNTwaZP1Q%40mail.gmail.com

```
Hi,

The most recent version of git crashes on gc command on my repository.
I've tracked it down to the segmentation fault in pack-objects.c while
running this command in the debugger:
gdb --args /usr/src/git/git-pack-objects.exe --local
--delta-base-offset .git/objects/pack/.tmp-14368-pack
--keep-true-parents --honor-pack-keep --non-empty --all --reflog
--indexed-objects --unpack-unreachable=2.weeks.ago --threads=1

It stops here:

#0  0x00007ff88b11de0e in ntdll!RtlLockHeap ()

   from C:\Windows\SYSTEM32\ntdll.dll

#1  0x00007ff88b11b7e4 in ntdll!RtlEnterCriticalSection ()

   from C:\Windows\SYSTEM32\ntdll.dll

#2  0x000000000047027c in oe_get_size_slow (pack=0x73fc20 <to_pack>,

    e=0x7ff5f7b03428) at builtin/pack-objects.c:1996

#3  0x000000000046ba27 in oe_set_size (pack=0x73fc20 <to_pack>,

    e=0x7ff5f7b03428, size=2987958784) at ./pack-objects.h:362

#4  0x000000000046f556 in check_object (entry=0x7ff5f7b03428)

    at builtin/pack-objects.c:1564

#5  0x000000000046ff63 in get_object_details () at builtin/pack-objects.c:1873

#6  0x0000000000471c11 in prepare_pack (window=10, depth=50)

    at builtin/pack-objects.c:2615

#7  0x0000000000474705 in cmd_pack_objects (argc=0, argv=0x2e30a48,

    prefix=0x0) at builtin/pack-objects.c:3491

#8  0x0000000000402e3b in run_builtin (p=0x680700 <commands+1728>, argc=12,

    argv=0x2e30a48) at git.c:421

#9  0x00000000004031f6 in handle_builtin (argc=12, argv=0x2e30a48)

    at git.c:653

#10 0x000000000040376b in cmd_main (argc=12, argv=0x2e30a48) at git.c:799

#11 0x00000000004bfb2f in main (argc=12, argv=0x2e30a48) at common-main.c:45


On the location builtin/pack-objects.c:1996 the code tries to set
read_lock (pthread_mutex_lock(&read_mutex)) and fails. I suspect that
read_mutex is not initialised yet. It is initialised in
init_threaded_search, which is called later in prepare_pack (through
ll_find_deltas).


Kind Regards,
Alex Netkachov

```

## Jeff King, 2019-01-22 07:29

Subject: Re: Potential bug in pack-objects.c
Message-ID: <20190122072946.GB28975@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20190122072946.GB28975%40sigill.intra.peff.net
In-Reply-To: <CAGAu0HVeQFA_O8_hsZbzRi9X35fF3DAeUaSd993JF=NTwaZP1Q@mail.gmail.com>

```
On Mon, Jan 21, 2019 at 10:10:16PM +0000, Alex Netkachov wrote:

> On the location builtin/pack-objects.c:1996 the code tries to set
> read_lock (pthread_mutex_lock(&read_mutex)) and fails. I suspect that
> read_mutex is not initialised yet. It is initialised in
> init_threaded_search, which is called later in prepare_pack (through
> ll_find_deltas).

This sounds like the same bug being discussed in:

  http://public-inbox.org/git/20190118022736.36832-1-phogg@novamoon.net/

-Peff

```

## Alex Netkachov, 2019-01-22 15:33

Subject: Re: Potential bug in pack-objects.c
Message-ID: <CAGAu0HW=N2nQr7zq_EVpegJDc6_womFDCLU5SCoCQw6cmzw8xg@mail.gmail.com>
URL: https://gitlist.dev/e/CAGAu0HW%3DN2nQr7zq_EVpegJDc6_womFDCLU5SCoCQw6cmzw8xg%40mail.gmail.com
In-Reply-To: <20190122072946.GB28975@sigill.intra.peff.net>

```
On Tue, 22 Jan 2019 at 07:29, Jeff King <peff@peff.net> wrote:
>
> On Mon, Jan 21, 2019 at 10:10:16PM +0000, Alex Netkachov wrote:
>
> > On the location builtin/pack-objects.c:1996 the code tries to set
> > read_lock (pthread_mutex_lock(&read_mutex)) and fails. I suspect that
> > read_mutex is not initialised yet. It is initialised in
> > init_threaded_search, which is called later in prepare_pack (through
> > ll_find_deltas).
>
> This sounds like the same bug being discussed in:
>
>   http://public-inbox.org/git/20190118022736.36832-1-phogg@novamoon.net/

It is exactly the same thing. Thank you. Hope it will be applied soon
and released.

Kind regards,
Alex

```
