Project

General

Profile

Actions

Bug #22330

closed

heap uaf from string.encode()

Bug #22330: heap uaf from string.encode()

Added by danielchong (Daniel Chong) 3 days ago. Updated 3 days ago.

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

Description

Hello, a heap UAF seems possible in string's encode function.

PoC

s = "あ" * 4000                                 
s.encode("US-ASCII",                                
         fallback: proc { |c|
           s.replace("Z" * (16 * 1024 * 1024))      
           "?"
         })

ASAN output (truncated):

ERROR: AddressSanitizer: heap-use-after-free ... READ of size 1
    #0 transcode_restartable0        transcode.c:592:36   (*in_p)
    #1 transcode_restartable         transcode.c:828
    #2 rb_transcoding_convert        transcode.c:864
    #3 trans_sweep                   transcode.c:1191
    #4 rb_trans_conv                  transcode.c:1281
    #5 rb_econv_convert0             transcode.c:1400
    #6 rb_econv_convert              transcode.c:1508
    #7 transcode_loop                transcode.c:2417   (goto resume -> rb_econv_convert)
    #8 str_transcode0                transcode.c:2877
    #9 str_transcode                 transcode.c:2907
    #10 str_encode                   transcode.c:2973
freed by thread T0 here:
    #15 proc_fallback               transcode.c:2340   (rb_proc_call -> user code reallocs source)
    #16 transcode_loop_fallback_try transcode.c:2366
    #18 transcode_loop              transcode.c:2433
Actions

Also available in: PDF Atom