From: Joseph Jones Date: 2015-12-17T21:06:01-07:00 Subject: [ruby-core:72252] [Ruby trunk - Bug #8543] new rb_iseq_load crash --56738629_25e45d32_16c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Joseph Jones liked your message with Boxer. On December 7, 2015 at 20:11:= 11 MST, usa=40garbagecollect.jp wrote:Issue =238543 has been updated by U= saku NAKAMURA.Backport changed from 2.0.0: UNKNOWN, 2.1: REQUIRED, 2.2: D= ONE to 2.0.0: UNKNOWN, 2.1: DONTNEED, 2.2: DONE2.0/2.1 use different code= about r51816.So they don't have this problem, I think.------------------= ----------------------Bug =238543: new rb=5Fiseq=5Fload crashhttps://bugs= .ruby-lang.org/issues/8543=23change-55336* Author: Alexey Voskov* Status:= Closed* Priority: Normal* Assignee: Koichi Sasada* ruby -v: -* Backport:= 2.0.0: UNKNOWN, 2.1: DONTNEED, 2.2: DONE--------------------------------= --------I noticed an unusual behaviour of undocumented rb=5Fiseq=5Fload f= unction. Its work differs in different Ruby versions. I'm trying to prote= ct some Rubysource code by its conversion to YARV p-code and using the ne= xt strategy:1. Convert code to array =7E=7E=7Eruby data =3D RubyVM::Instr= uctionSequence.compile=5Ffile('hello.rb').to=5Fa =7E=7E=7E2. Pass a compi= led source to the rb=5Fiseq=5Fload function and evaluate it =7E=7E=7Eruby= iseq =3D iseq=5Fload.(data) iseq.eval =7E=7E=7ESample programs are suppl= ied in the attachments.=22hello.rb=22=60=60=60rubyputs =22tralivali=22def= funct(a,b) a**bend3.times =7B =7Ci=7C puts =22Hello, world=23=7Bfunct(2,= i)=7D=21=22=7D=60=60=60The differencesRuby 1.9.3 (ruby 1.9.3p194 (2012-04= -20) =5Bi386-mingw32=5D)Correct work. Output:=60=60=60tralivaliHello, wor= ld1=21Hello, world2=21Hello, world4=21=60=60=60Ruby 2.0.0 (ruby 2.0.0p193= (2013-05-14) =5Bx64-mingw32=5D)Incorrect work (omits the code inside cod= e blocks). Output=60=60=60tralivali=60=60=60Attempts of loading bigger pr= ograms by means of rb=5Fiseq=5Fload in Ruby 2.0.0 usually ends with a seg= mentation fault.Such behaviour also can be reproduced by means of iseq Ru= by extension (=22for iseq freaks=22)https://github.com/wanabe/iseqP.S. I = understand that it is an undocumented feature.---=46iles-----------------= ---------------hello.rb (102 Bytes)rb=5Fpack.rb (931 Bytes)iseq-load-test= 3.rb (210 Bytes)iseq-load-test3-file.rb (369 Bytes)please-fix-rb=5Fiseq=5F= load-thank-you.pdf (444 KB)iseq-load-test5.rb (4.7 KB)-- https://bugs.rub= y-lang.org/ --56738629_25e45d32_16c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Joseph Jones liked your message with Boxer.


= On December 7, 2015 at 20:11:11 MST, usa=40garbagecollect.jp wrote:
<= blockquote type=3D=22cite=22 style=3D=22border-left-style:solid;border-wi= dth:1px;margin-left:0px;padding-left:10px;=22>Issue =238543 has been upda= ted by Usaku NAKAMURA.

Backport changed from 2.0.0: UNKNOWN, 2= .1: REQUIRED, 2.2: DONE to 2.0.0: UNKNOWN, 2.1: DONTNEED, 2.2: DONE
=
2.0/2.1 use different code about r51816.
So they don't have th= is problem, I think.

----------------------------------------<= br />Bug =238543: new rb=5Fiseq=5Fload crash
https://bugs.ruby-lang.= org/issues/8543=23change-55336

* Author: Alexey Voskov
* = Status: Closed
* Priority: Normal
* Assignee: Koichi Sasada
* ruby -v: -
* Backport: 2.0.0: UNKNOWN, 2.1: DONTNEED, 2.2: DONE<= br />----------------------------------------
I noticed an unusual b= ehaviour of undocumented rb=5Fiseq=5Fload function.
Its work differ= s 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

=7E=7E=7Eruby
data =3D= RubyVM::InstructionSequence.compile=5Ffile('hello.rb').to=5Fa
=7E= =7E=7E

2. Pass a compiled source to the rb=5Fiseq=5Fload funct= ion and evaluate it

=7E=7E=7Eruby
iseq =3D iseq=5Fl= oad.(data)
iseq.eval
=7E=7E=7E

Sample programs= are supplied in the attachments.
=22hello.rb=22

=60=60=60= ruby
puts =22tralivali=22
def funct(a,b)
a**b
end
3.times =7B =7Ci=7C
puts =22Hello, world=23=7Bfunct(2,i)= =7D=21=22
=7D
=60=60=60

The differences
Ruby 1.= 9.3 (ruby 1.9.3p194 (2012-04-20) =5Bi386-mingw32=5D)
Correct work. O= utput:

=60=60=60
tralivali
Hello, world1=21
Hel= lo, world2=21
Hello, world4=21
=60=60=60

Ruby 2.0.0 = (ruby 2.0.0p193 (2013-05-14) =5Bx64-mingw32=5D)
Incorrect work (omit= s the code inside code blocks). Output

=60=60=60
tralival= i
=60=60=60

Attempts of loading bigger programs by means = of rb=5Fiseq=5Fload in Ruby 2.0.0 usually ends with a segmentation fault.=

Such behaviour also can be reproduced by means of iseq Ruby e= xtension (=22for iseq freaks=22)
https://github.com/wanabe/iseq

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

<= br />---=46iles--------------------------------
hello.rb (102 Bytes)=
rb=5Fpack.rb (931 Bytes)
iseq-load-test3.rb (210 Bytes)
i= seq-load-test3-file.rb (369 Bytes)
please-fix-rb=5Fiseq=5Fload-thank= -you.pdf (444 KB)
iseq-load-test5.rb (4.7 KB)


-- https://bugs.ruby-lang.org/
--56738629_25e45d32_16c--