8134424: BlockDataInputStream.readUTFBody: size local StringBuffer with the given length

Reviewed-by: rriggs, shade
This commit is contained in:
Chris Hegarty 2016-02-15 14:25:21 +00:00
parent 7f68f6d847
commit 40965e0d6a

View File

@ -3144,7 +3144,15 @@ public class ObjectInputStream
* 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;
}