Project

General

Profile

Actions

Bug #22325

closed

out of bounds read in array

Bug #22325: out of bounds read in array

Added by danielchong (Daniel Chong) 11 days ago. Updated 6 days ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:126743]

Description

Hi, an OOB read seems possible in array

class bad < Numeric
  def initialize(v); @v = v; end
  def val; @v; end
  def <=>(o); @v <=> (o.is_a?(bad) ? o.val : o); end
  def to_int; $a.clear; @v; end
  def to_i; @v; end
  def coerce(o); [o, @v]; end
end
$a = (1..3000).to_a
seq = Range.new(bad.new(2900), bad.new(2950)).step(2)  

asan output (truncated):

ERROR: AddressSanitizer: heap-buffer-overflow ... READ of size 8 ...
    #0 ary_make_partial_step  array.c:1303
    #1 rb_ary_aref1           array.c:1947
    #2 vm_opt_aref            vm_insnhelper.c:7224
SUMMARY: AddressSanitizer: heap-buffer-overflow array.c:1303:9 in ary_make_partial_step

Updated by eightbitraptor (Matt V-H) 6 days ago Actions #2

  • Status changed from Open to Closed

Applied in changeset git|8befacf9e6c898a0f79dcb53bdd2e4cea24e0d1c.


Guard against oob read in rb_ary_aref1

When the array is shrunk during rb_arithmetic_sequence_beg_len_step,
ary_subseq_len returns -1. Return an empty array instead of passing the
negative length to ary_make_partial or ary_make_partial_step.

[Bug #22325]

Actions

Also available in: PDF Atom