Bug #410
closedbase64 decode flaw
Description
=begin
The following string is valid base64 data which does not decode properly with Base64.decode64(instr):
instr = "eyAiZXhwaXJhdGlvbiI6ICIyMDA3LTEyLTAxVDEyOjAwOjAwLjAwMFoiLAogICJjb25kaXRpb25zIjogWwogICAgeyJidWNrZXQiOiAiam9obnNtaXRoIn0sCiAgICBbInN0YXJ0cy13aXRoIiwgIiRrZXkiLCAidXNlci9lcmljLyJdLAogICAgeyJhY2wiOiAicHVibGljLXJlYWQifSwKICAgIHsic3VjY2Vzc19hY3Rpb25fcmVkaXJlY3QiOiAiaHR0cDovL2pvaG5zbWl0aC5zMy5hbWF6b25hd3MuY29tL3N1Y2Nlc3NmdWxfdXBsb2FkLmh0bWwifSwKICAgIFsic3RhcnRzLXdpdGgiLCAiJENvbnRlbnQtVHlwZSIsICJpbWFnZS8iXSwKICAgIHsieC1hbXotbWV0YS11dWlkIjogIjE0MzY1MTIzNjUxMjc0In0sCiAgICBbInN0YXJ0cy13aXRoIiwgIiR4LWFtei1tZXRhLXRhZyIsICIiXQogIF0KfQo="
This is sample data found here: http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?HTTPPOSTExamples.html
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": "http://johnsmith.s3.amazonaws.com/successful_upload.html"},
["starts-with", "$Content-Type", "image/"],
{"x-amz-meta-uuid": "14365123651274"},
["starts-with", "$x-amz-meta-tag", ""]
]
}'
=end
Updated by shyouhei (Shyouhei Urabe) over 16 years ago
=begin
Can't confirm... which version do you use?
=end
Updated by candlerb (Brian Candler) over 16 years ago
=begin
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 = "..."
instr.size
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 File.open(...) in irb to slurp in the data.
=end
Updated by ntucker (Neal Tucker) over 16 years ago
=begin
[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.
=end
Updated by ntucker (Neal Tucker) over 16 years ago
=begin
Further pondering...is 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.
=end
Updated by shyouhei (Shyouhei Urabe) almost 16 years ago
- Status changed from Open to Rejected
=begin
=end