changeset 13707:6e9ecae50b4e jdk-9+106

8134424: BlockDataInputStream.readUTFBody: size local StringBuffer with the given length Reviewed-by: rriggs, shade
author chegar
date Mon, 15 Feb 2016 14:25:21 +0000
parents 683b25e90142
children fec42527d470 01724c10f8ef 689c1a6f8768
files src/java.base/share/classes/java/io/ObjectInputStream.java
diffstat 1 files changed, 9 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/io/ObjectInputStream.java	Mon Feb 15 10:14:39 2016 +0000
+++ b/src/java.base/share/classes/java/io/ObjectInputStream.java	Mon Feb 15 14:25:21 2016 +0000
@@ -3144,7 +3144,15 @@
          * utflen bytes.
          */
         private String readUTFBody(long utflen) throws IOException {
-            StringBuilder sbuf = new StringBuilder();
+            StringBuilder sbuf;
+            if (utflen > 0 && utflen < Integer.MAX_VALUE) {
+                // a reasonable initial capacity based on the UTF length
+                int initialCapacity = Math.min((int)utflen, 0xFFFF);
+                sbuf = new StringBuilder(initialCapacity);
+            } else {
+                sbuf = new StringBuilder();
+            }
+
             if (!blkmode) {
                 end = pos = 0;
             }