Project

General

Profile

Actions

Bug #10913

closed

Enum#each_slice is crashing with Bignum as an argument

Added by pritamdey (arup rakshit) over 9 years ago. Updated over 9 years ago.

Status:
Third Party's Issue
Assignee:
-
Target version:
-
ruby -v:
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin12.0]
[ruby-core:68333]

Description

[shreyas@~ (master)]$ rvm use 2.1.2
Using /Users/shreyas/.rvm/gems/ruby-2.1.2
[shreyas@~ (master)]$ pry
`[1] pry(main)> [1,2,3].each_slice(50000000000000000).to_a
pry(948,0x7fff73abb180) malloc: *** mmap(size=400000000000000000) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
pry(948,0x7fff73abb180) malloc: *** mmap(size=400000000000000000) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
NoMemoryError: failed to allocate memory
from (pry):1:in `each_slice'
[2] pry(main)>`

Updated by Hanmac (Hans Mackowiak) over 9 years ago

i cant repoduce it with my ruby versions 2.1.2 and ruby 2.3.0dev

[1] pry(main)> [1,2,3].each_slice(500000000000000000).to_a
NoMemoryError: failed to allocate memory
from (pry):1:in `each_slice'
[2] pry(main)> [1,2,3].each_slice(5000000000000000000).to_a
ArgumentError: array size too big
from (pry):2:in `each_slice'
[3] pry(main)> [1,2,3].each_slice(50000000000000000000).to_a
RangeError: bignum too big to convert into `long'
from (pry):3:in `each_slice'

imo each_slice might be optimiced if the parameter is bigger than the total array/enum size ...

Updated by pritamdey (arup rakshit) over 9 years ago

[shreyas@so (master)]$ rvm list

rvm rubies

=> ruby-2.0.0-p598 [ x86_64 ]
   ruby-2.1.0 [ x86_64 ]
 * ruby-2.1.2 [ x86_64 ]
   ruby-2.1.4 [ x86_64 ]
   ruby-2.1.5 [ x86_64 ]
   ruby-2.2.0 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

[shreyas@so (master)]$ rvm use 2.0.0
Using /Users/shreyas/.rvm/gems/ruby-2.0.0-p598
[shreyas@so (master)]$ irb
cannot load such file -- interactive_editor
2.0.0-p598 :001 > [1,2,3].each_slice(50000000000000000).to_a
irb(47601,0x7fff73abb180) malloc: *** mmap(size=400000000000000000) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
irb(47601,0x7fff73abb180) malloc: *** mmap(size=400000000000000000) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
NoMemoryError: failed to allocate memory
	from (irb):1:in `each_slice'
	from (irb):1:in `each'
	from (irb):1:in `to_a'
	from (irb):1
	from /Users/shreyas/.rvm/rubies/ruby-2.0.0-p598/bin/irb:12:in `<main>'
2.0.0-p598 :002 > exit
[shreyas@so (master)]$ rvm use 2.1.5
Using /Users/shreyas/.rvm/gems/ruby-2.1.5
[shreyas@so (master)]$ irb
cannot load such file -- interactive_editor
2.1.5 :001 > [1,2,3].each_slice(50000000000000000).to_a
irb(47687,0x7fff73abb180) malloc: *** mmap(size=400000000000000000) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
irb(47687,0x7fff73abb180) malloc: *** mmap(size=400000000000000000) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
NoMemoryError: failed to allocate memory
	from (irb):1:in `each_slice'
	from (irb):1:in `each'
	from (irb):1:in `to_a'
	from (irb):1
	from /Users/shreyas/.rvm/rubies/ruby-2.1.5/bin/irb:11:in `<main>'
2.1.5 :002 > exit
[shreyas@so (master)]$ rvm use 2.2.0
Using /Users/shreyas/.rvm/gems/ruby-2.2.0
[shreyas@so (master)]$ irb
cannot load such file -- interactive_editor
2.2.0 :001 > [1,2,3].each_slice(50000000000000000).to_a
irb(47773,0x7fff73abb180) malloc: *** mmap(size=400000000000000000) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
irb(47773,0x7fff73abb180) malloc: *** mmap(size=400000000000000000) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
NoMemoryError: failed to allocate memory
	from (irb):1:in `each_slice'
	from (irb):1:in `each'
	from (irb):1:in `to_a'
	from (irb):1
	from /Users/shreyas/.rvm/rubies/ruby-2.2.0/bin/irb:11:in `<main>'
2.2.0 :002 >

Another information is :

2.2.0 :002 > RbConfig::CONFIG["CC"]
=> "/usr/bin/clang"
2.2.0 :003 >

Updated by nobu (Nobuyoshi Nakada) over 9 years ago

  • Description updated (diff)
  • Status changed from Open to Third Party's Issue

It reproduces with just:

Array.new(50000000000000000)

and

"x"*50000000000000000

The failure itself is expected, but OSX's malloc complains.

Seems there is no hook to control it.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0