8134424: BlockDataInputStream.readUTFBody: size local StringBuffer with the given length
Reviewed-by: rriggs, shade
--- a/jdk/src/java.base/share/classes/java/io/ObjectInputStream.java Mon Feb 15 10:14:39 2016 +0000
+++ b/jdk/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;
}