Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Force this buffer to BINARY encoding
This buffer is used by a few tests that wrap non-IO objects with a duck-typed wrapper, as seen here: def z.read(size @buf ||= TestZlib.create_gzip_stream("hello") @buf.slice!(0, size) end If this buffer is not encoded as BINARY, then the slice! call may treat the requested length as a character count. With the buffer using the default UTF-8 this may lead to binary bytes being misinterpreted as prefix bytes, and the resulting slice will contain more bytes than were requested. This is bad form for an IO#read implementation; it should never return more bytes than requested. A second bug in IOInputStream blindly attempts to copy all those bytes into its buffer, resulting in an ArrayIndexOutOfBoundsException (bug #1 in jruby#8391). The fix here opens the StringIO using encoding: "BINARY" to ensure the slice length can only be interpreted as a byte count, so the read slicing never returns more than the number of bytes requested. Partial fix for jruby#8391.
- Loading branch information