Skip to content

Base64.strict_decode64 isn't strict #2551

Description

@blinsay

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.

Activity

  1. rtyler commented on Mar 16, 2015

    @rtyler

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

  2. blinsay commented on Mar 16, 2015

    @blinsay
    Author

    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'
    
  3. mkristian commented on Mar 19, 2015

    @mkristian
    Member

    fixed with 13ff7bf

  4. added this to the JRuby 1.7.20 milestone on Mar 19, 2015
  5. blinsay commented on Mar 24, 2015

    @blinsay
    Author

    awesome! thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions