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

Base64.strict_decode64 isn't strict #2551

Closed
blinsay opened this Issue Feb 2, 2015 · 4 comments

Comments

Projects
None yet
4 participants
@blinsay
Copy link

commented Feb 2, 2015

JRuby's Base64.strict_decode64 doesn't seem to actually be strict. It's easy to reproduce in a REPL.

[5] pry(main)> d = Base64.strict_encode64("hi there")
=> "aGkgdGhlcmU="
[6] pry(main)> Base64.strict_decode64("aGkgdGhlcmU")
=> "hi the"

Using IRB in Ruby 2.0p481, the method actually throws an invalid base64 error.

irb(main):007:0> Base64.strict_encode64("hi there")
=> "aGkgdGhlcmU="
irb(main):008:0> Base64.strict_decode64("aGkgdGhlcmU")
ArgumentError: invalid base64
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/base64.rb:73:in `unpack'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/base64.rb:73:in `strict_decode64'
    from (irb):8
    from /usr/bin/irb:12:in `<main>'

I took a quick peek, and the Ruby source in the Base64 modules of both versions looks identical. Didn't have time to dive into pack to see what was going on.

@rtyler

This comment has been minimized.

Copy link

commented Mar 16, 2015

Which version of JRuby are you working with in the first version?

@blinsay

This comment has been minimized.

Copy link
Author

commented Mar 16, 2015

It's happening on 1.7.9, 1.7.16, and 9000-pre.

[12:44:00] benl:jruby-testing $ rbenv local jruby-1.7.9
[12:44:09] benl:jruby-testing $ ruby base64_strict_test.rb
test string = 'hi there'
encoded = aGkgdGhlcmU=
Base64.strict_decode64(aGkgdGhlcmU)
decoded = 'hi the'
[12:44:12] benl:jruby-testing $ rbenv local jruby-1.7.16
[12:44:15] benl:jruby-testing $ ruby base64_strict_test.rb
test string = 'hi there'
encoded = aGkgdGhlcmU=
Base64.strict_decode64(aGkgdGhlcmU)
decoded = 'hi the'
[12:44:18] benl:jruby-testing $ rbenv local jruby-9.0.0.0.pre1
[12:44:27] benl:jruby-testing $ ruby base64_strict_test.rb
test string = 'hi there'
encoded = aGkgdGhlcmU=
Base64.strict_decode64(aGkgdGhlcmU)
decoded = 'hi the'
@mkristian

This comment has been minimized.

Copy link
Member

commented Mar 19, 2015

fixed with 13ff7bf

@mkristian mkristian closed this Mar 19, 2015

@mkristian mkristian removed the in progress label Mar 19, 2015

@kares kares added this to the JRuby 1.7.20 milestone Mar 19, 2015

@blinsay

This comment has been minimized.

Copy link
Author

commented Mar 24, 2015

awesome! thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.