8011135: (bf) CharBuffer.put(String) is slow because of String.charAt() call for each char

Brian Burkhalter brian.burkhalter at oracle.com
Thu Feb 21 17:49:50 UTC 2019

> On Feb 21, 2019, at 9:45 AM, Alan Bateman <Alan.Bateman at oracle.com> wrote:
> On 21/02/2019 17:41, Brian Burkhalter wrote:
>>> There are a few other places in the heap buffers that also need to be hardened a bit (direct buffers of course need to much more careful).
>> Shall I try to include fixing those in this patch?
> Probably best to do it as a separate issue. I try to watch for these things with direct buffer classes as these could lead to any number of VM crashes or security issues. It's a less of concern with the heap buffers but would be good to fix if you have cycles.

Updated patch below. It’s a little unclear where to put ‘pos = position()’. I’ll file a separate issue for other hardening instances.



+    public $Type$Buffer put(String src, int start, int end) {
+        int length = end - start;
+        checkBounds(start, length, src.length());
+        if (isReadOnly())
+            throw new ReadOnlyBufferException();
+        if (length > remaining())
+            throw new BufferOverflowException();
+        int pos = position();
+        src.getChars(start, end, hb, ix(pos));
+        position(pos + length);
+        return this;
+    }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/nio-dev/attachments/20190221/79beced5/attachment.html>

More information about the nio-dev mailing list