Project

General

Profile

Actions

Bug #22326

closed

heap buffer overflow in array.values_at()

Bug #22326: heap buffer overflow in array.values_at()

Added by danielchong (Daniel Chong) about 2 months ago. Updated about 1 month ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
4.1.0dev
[ruby-core:126744]

Description

Hello, I discovered a heap buffer overflow in array.values_at(). I believe the root issue/potential fix is similar to #22325, but the code paths are distinct.

PoC:

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
$a.values_at(Range.new(bad.new(2900), bad.new(2950)))   

asan output (truncated):

ERROR: AddressSanitizer: heap-buffer-overflow ... READ of size 408 ...
    #3 ary_memcpy0             array.c:354
    #4 rb_ary_cat              array.c:1417
    #5 append_values_at_single array.c:3970
    #6 rb_ary_values_at        array.c:4096

Updated by peterzhu2118 (Peter Zhu) about 2 months ago Actions #1 [ruby-core:126789]

  • Backport changed from 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN to 3.3: WONTFIX, 3.4: REQUIRED, 4.0: REQUIRED

Thank you for this bug report. I believe this PR should have fixed this bug. I will mark this issue for backport.

Updated by mame (Yusuke Endoh) about 1 month ago Actions #2

  • Status changed from Open to Closed

Updated by k0kubun (Takashi Kokubun) about 1 month ago Actions #3 [ruby-core:127055]

  • Backport changed from 3.3: WONTFIX, 3.4: REQUIRED, 4.0: REQUIRED to 3.3: WONTFIX, 3.4: REQUIRED, 4.0: DONE

Updated by nagachika (Tomoyuki Chikanaga) about 1 month ago Actions #4 [ruby-core:127077]

  • Backport changed from 3.3: WONTFIX, 3.4: REQUIRED, 4.0: DONE to 3.3: WONTFIX, 3.4: DONE, 4.0: DONE
Actions

Also available in: PDF Atom