提交 9b0bcd1b 编写于 作者: M mchung

6631046: BufferedInputStream.available() reports negative int on very large inputstream

Reviewed-by: dholmes, alanb, mduigou
上级 f541c96a
...@@ -395,7 +395,11 @@ class BufferedInputStream extends FilterInputStream { ...@@ -395,7 +395,11 @@ class BufferedInputStream extends FilterInputStream {
* or an I/O error occurs. * or an I/O error occurs.
*/ */
public synchronized int available() throws IOException { public synchronized int available() throws IOException {
return getInIfOpen().available() + (count - pos); int n = count - pos;
int avail = getInIfOpen().available();
return n > (Integer.MAX_VALUE - avail)
? Integer.MAX_VALUE
: n + avail;
} }
/** /**
......
...@@ -273,7 +273,11 @@ class PushbackInputStream extends FilterInputStream { ...@@ -273,7 +273,11 @@ class PushbackInputStream extends FilterInputStream {
*/ */
public int available() throws IOException { public int available() throws IOException {
ensureOpen(); ensureOpen();
return (buf.length - pos) + super.available(); int n = buf.length - pos;
int avail = super.available();
return n > (Integer.MAX_VALUE - avail)
? Integer.MAX_VALUE
: n + avail;
} }
/** /**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册