[erlang-bugs] 2#1 bsl N Crashes Erlang (x86_64)

Daniel Hedlund <>
Sun Feb 1 10:31:00 CET 2009


This bug affects x86_64 implementations.  Not sure if it's OS specific
or affects other 64-bit architectures.  2#1 bsl N crashes Erlang when
N is larger than available memory but lower than 2^59.  Above 2^59, a
bad argument exception occurs.

It appears there's supposed to be a check that prevents insanely large
values of N, starting at 2^25-64 (64-bit) and 2^24-32 (32-bit); at
this point it starts returning "a system limit has been reached".  On
32-bit systems, this check works all the way up through the bad
argument exception mentioned above.  On 64-bit, this check stops
working where 2^34 < N < 2^35; it begins attempting to allocate memory
again, eventually crashing.

Running Fedora 10 (x86_64).  Both R12B-4 (via
erlang-R12B-4.3.fc10.x86_64.rpm) and R12B-5 (latest source w/ OTP-7738
patch) affected:

Erlang (BEAM) emulator version 5.6.5 [source] [64-bit] [smp:2]
[async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.6.5  (abort with ^G)
1> 2#1 bsl (trunc(math:pow(2,34))-1).
** exception error: a system limit has been reached
     in operator  bsl/2
        called as 1 bsl 17179869183
2> 2#1 bsl (trunc(math:pow(2,35))).

Crash dump was written to: erl_crash.dump
eheap_alloc: Cannot allocate 4454408120 bytes of memory (of type "heap").
Aborted

...

Eshell V5.6.5  (abort with ^G)
1> 2#1 bsl trunc(math:pow(2,59)).
** exception error: bad argument in an arithmetic expression
     in operator  bsl/2
        called as 1 bsl 576460752303423488
2> 2#1 bsl (trunc(math:pow(2,59))-1).

Crash dump was written to: erl_crash.dump
eheap_alloc: Cannot allocate 72057594037928000 bytes of memory (of
type "heap_frag").
Aborted


Core dump available on request.

Cheers,

Daniel Hedlund




More information about the erlang-bugs mailing list