Skip to content

Commit

Permalink
Don't view the same buffer; it might be updated while in use.
Browse files Browse the repository at this point in the history
Due to a bug in how Enumerator#next progresses (it will run an
iteration ahead of requested) this bug was exposed as #4903 where
an Enumerator#next-based sink for IO.copy_stream showed
previously-returned results getting modified after handoff. The
same buffer array was being shared across all chunks written,
which works ok if that view were only used within the confines of
copy_stream, but in this case the chunks were held across more
than a single write.

Fixes #4903.

See #5007 for the Enumerator#next bug.
headius committed Jan 24, 2018

Verified

This commit was signed with the committer’s verified signature.
headius Charles Oliver Nutter
1 parent cce8776 commit c9bfede
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/util/IOChannel.java
Original file line number Diff line number Diff line change
@@ -97,7 +97,7 @@ protected int write(CallSite write, ByteBuffer src) throws IOException {
ByteList buffer;

if (src.hasArray()) {
buffer = new ByteList(src.array(), src.position(), src.remaining(), false);
buffer = new ByteList(src.array(), src.position(), src.remaining(), true);
} else {
buffer = new ByteList(src.remaining());
buffer.append(src, src.remaining());

0 comments on commit c9bfede

Please sign in to comment.