[erlang-bugs] Segmentation fault with ETS bag implementation in 64-bit Erlang

Sverker Eriksson <>
Mon Feb 20 14:01:59 CET 2012


Here is a preliminary source patch:

diff --git a/erts/emulator/beam/big.c b/erts/emulator/beam/big.c
index 976f05c..8848741 100644
--- a/erts/emulator/beam/big.c
+++ b/erts/emulator/beam/big.c
@@ -1867,9 +1867,12 @@ Eterm bytes_to_big(byte *xp, dsize_t xsz, int 
xsgn, Eterm *r)
        d = 0;
        for(i = xsz; --i >= 0;)
            d = (d << 8) | xp[i];
+       if (++rsz == 1 && IS_USMALL(xsgn,d)) {
+           if (xsgn) d = -d;
+           return make_small(d);
+       }
        *rwp = d;
        rwp++;
-       rsz++;
     }
     return big_norm(r, rsz, (short) xsgn);
 }


Sverker Eriksson wrote:
> Hi Diego,
>
> Thanks for the exemplary test code to provoke the bug. I get the same 
> crash on my 64-bit machine.
>
> I think I found what it is. To be continued on Monday...
>
> /Sverker, Erlang/OTP, Ericsson
>
> Diego Llarrull wrote:
>> Hello everyone,
>>
>> I'm currently developing a distributed store written entirely in 
>> Erlang, and we are having a somewhat awkward problem: the app runs 
>> fine in 32-bit Erlang VMs but ALWAYS crashes in 64-bit Erlang VMs.
>> We've tested 64-bit Erlang VMs running on Linux (XUbuntu 11.04/Fedora 
>> 15) 64-bit, OS X Lion 64-bit, and FreeBSD 8.2 64-bit with exactly the 
>> same result: a segmentation fault as soon as we try to
>> to use the store.
>>
>> We managed to track down one bug, which was caused by inserting the 
>> same record twice, on a compressed, named ETS table with bag 
>> implementation. This causes, inexplicably, a segmentation fault which
>> is solved my changing the Ets table to a set.
>>
>>
>> To replicate the bug, the following code can be run:
>>
>>     -module(segviola14).
>>     -compile(export_all).
>>
>>     init() ->
>>     S =     {
>>                {1316110174588445,1316110174588583},
>>                {1316110174588445,1316110174588590}
>>     },
>>     DB=ets:new(childName, [named_table, bag, compressed]),
>>     ets:insert(DB, S), io:format("guau!~n"),
>>     ets:insert(DB, S), io:format("guau!~n").
>>
>>         The output for this code is:
>>
>>>  segviola14:init().
>> guau!
>> Segmentation fault (core dumped)
>>
>>
>> In 32-bit Erlang VMs this code works just fine. We are, however, 
>> having segmentation faults throught our code that make us think the 
>> bug affects a core area of the VM-code. 32-bit Erlang showed
>> none of these problems, with everything running fine.
>>
>> Any ideas?
>>
>> Thank you all in advance.
>>
>>
>> Diego
>>
>>  
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> erlang-bugs mailing list
>> 
>> http://erlang.org/mailman/listinfo/erlang-bugs
>>   
>
>
> _______________________________________________
> erlang-bugs mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-bugs
>




More information about the erlang-bugs mailing list