Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array#pack raises an internal exception when called with <L or >L #2791

Closed
postmodern opened this issue Nov 20, 2022 · 3 comments
Closed

Array#pack raises an internal exception when called with <L or >L #2791

postmodern opened this issue Nov 20, 2022 · 3 comments
Assignees
Labels
compatibility third-party-issue An issue which should be fixed upstream

Comments

@postmodern
Copy link

I ran into an issue with Array#pack when trying to get my test suite passing on truffleruby-22.3.0. I was able to isolate the issue to calling Array#pack with <L or >L.

Steps To Reproduce

[0].pack('<L')

Expected Result

"\x00\x00\x00\x00"

Actual Result

truffleruby: an internal exception escaped out of the interpreter,
please report it to https://github.com/oracle/truffleruby/issues.

> (java.lang.UnsupportedOperationException)
	from org.truffleruby.core.format.pack.SimplePackParser.parse(SimplePackParser.java:429)
	from org.truffleruby.core.format.pack.PackCompiler.compile(PackCompiler.java:41)
	from org.truffleruby.core.array.ArrayNodes$PackNode.compileFormat(ArrayNodes.java:1614)
	from org.truffleruby.core.array.ArrayNodesFactory$PackNodeFactory$PackNodeGen.executeAndSpecialize(ArrayNodesFactory.java:7796)
	from org.truffleruby.core.array.ArrayNodesFactory$PackNodeFactory$PackNodeGen.execute(ArrayNodesFactory.java:7755)
	from org.truffleruby.language.RubyCoreMethodRootNode.execute(RubyCoreMethodRootNode.java:48)
(irb):2:in `pack'
	from (irb):2:in `<top (required)>'
	from /opt/rubies/truffleruby-22.3.0/lib/mri/irb/workspace.rb:116:in `evaluate'
	from /opt/rubies/truffleruby-22.3.0/lib/mri/irb/context.rb:450:in `evaluate'
	from /opt/rubies/truffleruby-22.3.0/lib/mri/irb.rb:567:in `block (2 levels) in eval_input'
	from /opt/rubies/truffleruby-22.3.0/lib/mri/irb.rb:751:in `signal_status'
	from /opt/rubies/truffleruby-22.3.0/lib/mri/irb.rb:548:in `block in eval_input'
	from /opt/rubies/truffleruby-22.3.0/lib/mri/irb/ruby-lex.rb:251:in `block (2 levels) in each_top_level_statement'
	from <internal:core> core/kernel.rb:407:in `loop'
	from /opt/rubies/truffleruby-22.3.0/lib/mri/irb/ruby-lex.rb:233:in `block in each_top_level_statement'
	from <internal:core> core/throw_catch.rb:36:in `catch'
	from /opt/rubies/truffleruby-22.3.0/lib/mri/irb/ruby-lex.rb:232:in `each_top_level_statement'
	from /opt/rubies/truffleruby-22.3.0/lib/mri/irb.rb:547:in `eval_input'
	from /opt/rubies/truffleruby-22.3.0/lib/mri/irb.rb:481:in `block in run'
	from <internal:core> core/throw_catch.rb:36:in `catch'
	from /opt/rubies/truffleruby-22.3.0/lib/mri/irb.rb:480:in `run'
	from /opt/rubies/truffleruby-22.3.0/lib/mri/irb.rb:409:in `start'
	from /opt/rubies/truffleruby-22.3.0/lib/gems/gems/irb-1.3.5/exe/irb:11:in `<top (required)>'
	from <internal:core> core/kernel.rb:376:in `load'
	from <internal:core> core/kernel.rb:376:in `load'
	from /opt/rubies/truffleruby-22.3.0/bin/irb:42:in `<main>'

Additional Information

  • truffleruby 22.3.0, like ruby 3.0.3, GraalVM CE Native [x86_64-linux]
@eregon
Copy link
Member

eregon commented Nov 21, 2022

>/< should be suffixed according to docs: https://docs.ruby-lang.org/en/master/packed_data_rdoc.html#label-Modifiers+for+Integer+Directives

It seems a bug that CRuby accepts them before and in fact it seems to ignore them (!):

irb(main):007:0> RUBY_DESCRIPTION
=> "ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux]"
irb(main):008:0> [1].pack('<L')
=> "\x01\x00\x00\x00"
irb(main):009:0> [1].pack('>L')
=> "\x01\x00\x00\x00"

irb(main):012:0> [1].pack('L<')
=> "\x01\x00\x00\x00"
irb(main):013:0> [1].pack('L>')
=> "\x00\x00\x00\x01"

TruffleRuby works fine with the correct L</L>.

So <L is a bug of the caller code, and probably a bug of CRuby too.
It would be great if you can report this to CRuby.

TruffleRuby should raise a proper Ruby exception though for this case, probably an ArgumentError.

@eregon eregon added the third-party-issue An issue which should be fixed upstream label Nov 21, 2022
@andrykonchin andrykonchin self-assigned this Nov 21, 2022
@eregon
Copy link
Member

eregon commented Nov 21, 2022

As @andrykonchin found, there is actually a warning on CRuby with $VERBOSE=true:

$ ruby -v -e "p [0].pack('<L')"
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux]
<internal:pack>:144: warning: unknown pack directive '<' in '<L'
"\x00\x00\x00\x00"

Which seems somewhat related to https://bugs.ruby-lang.org/issues/19108.

postmodern added a commit to ronin-rb/ronin-exploits that referenced this issue Dec 8, 2022
@andrykonchin
Copy link
Member

Fixed in e2940ef. Thank you for reporting!

The decision is to warn unconditionally in Ruby 3.2 and to raise an exception in the next Ruby version. The issue - https://bugs.ruby-lang.org/issues/19150.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility third-party-issue An issue which should be fixed upstream
Projects
None yet
Development

No branches or pull requests

3 participants