Skip to content

IO#read does not clear code-range for buffer argument #9035

@kares

Description

@kares

Environment Information

Failing in both latest JRuby 9.4.14.0 and 10.0.2.0

For context, this started as a Rails file-upload (windows-1252) encoding issue.
Rack's multi-part implementation re-uses a String.new buffer and the incorrect code-range (upon second or later read) ends up causing an ArgumentError: invalid byte sequence in UTF-8.

tmpfile = Tempfile.new('file')
tmpfile.open
tmpfile.write("0123456789", tmpfile.path)
tmpfile.flush
tmpfile.close

### ------------------------------------------------

buf.concat "¿Cómo estás? Ça va bien?"

puts buf.ascii_only? # false

# open and read from a file with ASCII only content e.g.
File.open(tmpfile.path, encoding: 'binary') do |file|
  file.read(10, buf) # read less than buf.size
end

tmpfile.delete

puts buf.inspect
puts buf.ascii_only? # true on MRI but false on JRuby

The last ascii_only? check fails as the code-range is not cleared upon re-using the buffer on IO#read.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions