diff options
author | rhe <rhe@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-12-20 05:26:08 +0000 |
---|---|---|
committer | rhe <rhe@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-12-20 05:26:08 +0000 |
commit | 647ba111ea0b2d6de5454abe6daece75c08ad905 (patch) | |
tree | a233c4258ad27cda9d4fd0b7157dc43cd4220f31 /test/ruby | |
parent | c54ede0560be7e57b90b063fcddab402f4f29cd3 (diff) |
array.c: check array length every time after yielding
Since the Array may be modified during rb_yield(), the length before
invoking the block can't be trusted. Fix possible out-of-bounds read in
Array#combination and Array#repeated_combination.
It may better to make a defensive copy of the Array, but for now let's
follow what Array#permutation does. [ruby-core:78738] [Bug #13052]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57119 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_array.rb | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index 6ac2ff1c80..563a37ee2e 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -2483,11 +2483,18 @@ class TestArray < Test::Unit::TestCase def test_combination_clear bug9939 = '[ruby-core:63149] [Bug #9939]' - assert_ruby_status([], <<-'end;', bug9939) - 100_000.times {Array.new(1000)} + assert_nothing_raised(bug9939) { a = [*0..100] a.combination(3) {|*,x| a.clear} - end; + } + + bug13052 = '[ruby-core:78738] [Bug #13052] Array#combination segfaults if the Array is modified during iteration' + assert_nothing_raised(bug13052) { + a = [*0..100] + a.combination(1) { a.clear } + a = [*0..100] + a.repeated_combination(1) { a.clear } + } end def test_product2 |