Bug #410


base64 decode flaw

Added by Anonymous almost 15 years ago. Updated about 12 years ago.

ruby -v:


The following string is valid base64 data which does not decode properly with Base64.decode64(instr):
instr = "eyAiZXhwaXJhdGlvbiI6ICIyMDA3LTEyLTAxVDEyOjAwOjAwLjAwMFoiLAogICJjb25kaXRpb25zIjogWwogICAgeyJidWNrZXQiOiAiam9obnNtaXRoIn0sCiAgICBbInN0YXJ0cy13aXRoIiwgIiRrZXkiLCAidXNlci9lcmljLyJdLAogICAgeyJhY2wiOiAicHVibGljLXJlYWQifSwKICAgIHsic3VjY2Vzc19hY3Rpb25fcmVkaXJlY3QiOiAiaHR0cDovL2pvaG5zbWl0aC5zMy5hbWF6b25hd3MuY29tL3N1Y2Nlc3NmdWxfdXBsb2FkLmh0bWwifSwKICAgIFsic3RhcnRzLXdpdGgiLCAiJENvbnRlbnQtVHlwZSIsICJpbWFnZS8iXSwKICAgIHsieC1hbXotbWV0YS11dWlkIjogIjE0MzY1MTIzNjUxMjc0In0sCiAgICBbInN0YXJ0cy13aXRoIiwgIiR4LWFtei1tZXRhLXRhZyIsICIiXQogIF0KfQo="

This is sample data found here:

The decoded data should be a valid JSON blob that looks like this:

'{ "expiration": "2007-12-01T12:00:00.000Z",
"conditions": [
{"bucket": "johnsmith"},
["starts-with", "$key", "user/eric/"],
{"acl": "public-read"},
{"success_action_redirect": ""},
["starts-with", "$Content-Type", "image/"],
{"x-amz-meta-uuid": "14365123651274"},
["starts-with", "$x-amz-meta-tag", ""]

Actions #1

Updated by shyouhei (Shyouhei Urabe) almost 15 years ago

Can't confirm... which version do you use?


Actions #2

Updated by candlerb (Brian Candler) almost 15 years ago

And how does the corrupted output look?

I can replicate a similar problem here by pasting the string into irb, but it turned out to be nothing more than a lost character during pasting. This is under Ubuntu Hardy and Gnome terminal:

 instr = "..."

This shows instr to be 527 characters, when in fact it should be 528 (not including any newline). The unpacked result looks like this:

 ["starts-with", "$x-amz-meta-ta??B B?B

However I can paste that string directly into the Unix shell just fine: i.e.

 ruby -e 'puts "...".unpack("m").first'

and get the correct answer. So it seems to be just a problem with Unix pasting or readline, not with Ruby's base64 decoding.

You can fix this by pasting into a file, and using in irb to slurp in the data.


Actions #3

Updated by ntucker (Neal Tucker) almost 15 years ago

[Note: this was my bug; I registered so I could follow up]

Sure enough, this is not a ruby bug. I never would have guessed pasting text into gnome terminal would result in random character dropping, but there you go. I compared the pasted string to a copy read from a file and there is a single character missing from the middle.

This can be closed.

Actions #4

Updated by ntucker (Neal Tucker) almost 15 years ago

Further it possible this is an irb bug having to do with input handling? I ask because it reproduces nearly 100% of the time in irb, but never in, say vi running in the same terminal.


Actions #5

Updated by shyouhei (Shyouhei Urabe) over 14 years ago

  • Status changed from Open to Rejected




Also available in: Atom PDF