Skip to content

Instantly share code, notes, and snippets.

@marshalium
Created April 21, 2015 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marshalium/e6bf93b06949890c695d to your computer and use it in GitHub Desktop.
Save marshalium/e6bf93b06949890c695d to your computer and use it in GitHub Desktop.
JRuby encode bug examples
=begin
Here are some base64 encoded sequences of bytes that cause JRuby to hang:
7bWdZw==
7by/Vg==
DO27qA==
7bu1Lg==
UhbtqbHF04o=
bjlSh+2guiM=
NOrtppL+zQA=
7b27A0BGi5w=
4fGnt05Uqe2jqI7RKi664g==
7aa4Ne2wUuJb9ozCry1aqw==
gzEH7bWg2hvaUVohitrNRA==
meXI23O/mZrAX8u27bG3OQ==
=end
# Here is the script I used to find them.
require 'base64'
NUM_BYTES = 16
rand = Random.new
while true
data = rand.bytes(NUM_BYTES)
data.force_encoding("UTF-8")
puts "data=#{Base64.encode64(data)}"
puts "Before calling encode: data.length=#{data.length}"
data = data.encode("UTF-16", :undef => :replace, :invalid => :replace, :replace => '')
puts "After calling encode: data.length=#{data.length}"
puts "\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment