Project

General

Profile

Actions

Bug #8543

closed

new rb_iseq_load crash

Added by alvoskov (Alexey Voskov) almost 11 years ago. Updated over 8 years ago.

Status:
Closed
Target version:
-
[ruby-core:55557]

Description

I noticed an unusual behaviour of undocumented rb_iseq_load function.
Its work differs in different Ruby versions. I'm trying to protect some Ruby
source code by its conversion to YARV p-code and using the next strategy:

  1. Convert code to array

    data = RubyVM::InstructionSequence.compile_file('hello.rb').to_a
    
  2. Pass a compiled source to the rb_iseq_load function and evaluate it

    iseq = iseq_load.(data)
    iseq.eval
    

Sample programs are supplied in the attachments.
"hello.rb"

puts "tralivali"
def funct(a,b)
  a**b
end

3.times { |i|
  puts "Hello, world#{funct(2,i)}!"
}

The differences
Ruby 1.9.3 (ruby 1.9.3p194 (2012-04-20) [i386-mingw32])
Correct work. Output:

tralivali
Hello, world1!
Hello, world2!
Hello, world4!

Ruby 2.0.0 (ruby 2.0.0p193 (2013-05-14) [x64-mingw32])
Incorrect work (omits the code inside code blocks). Output

tralivali

Attempts of loading bigger programs by means of rb_iseq_load in Ruby 2.0.0 usually ends with a segmentation fault.

Such behaviour also can be reproduced by means of iseq Ruby extension ("for iseq freaks")
https://github.com/wanabe/iseq

P.S. I understand that it is an undocumented feature.


Files

hello.rb (102 Bytes) hello.rb Codes for conversion to YARV PCODE alvoskov (Alexey Voskov), 06/19/2013 09:39 PM
rb_pack.rb (931 Bytes) rb_pack.rb "Compiler" alvoskov (Alexey Voskov), 06/19/2013 09:39 PM
iseq-load-test3.rb (210 Bytes) iseq-load-test3.rb Program which calls RubyVM::InstructionSequence.load spatulasnout (B Kelly), 04/16/2014 10:03 AM
iseq-load-test3-file.rb (369 Bytes) iseq-load-test3-file.rb Program fragment which triggers SEGV when loaded by rb_iseq_load spatulasnout (B Kelly), 04/16/2014 10:03 AM
please-fix-rb_iseq_load-thank-you.pdf (444 KB) please-fix-rb_iseq_load-thank-you.pdf PDF slide describing our use case for rb_iseq_load, per: [ruby-core:63332] spatulasnout (B Kelly), 06/26/2014 11:36 PM
iseq-load-test5.rb (4.7 KB) iseq-load-test5.rb Small ruby program reproducing iseq_load crash spatulasnout (B Kelly), 09/09/2015 11:25 PM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0