changeset 7280:81f10887bf74

6631046: BufferedInputStream.available() reports negative int on very large inputstream Reviewed-by: dholmes, alanb, mduigou
author mchung
date Fri, 19 Nov 2010 10:00:08 -0800
parents 32ac37aa9367
children f202e1a7a134
files jdk/src/share/classes/java/io/BufferedInputStream.java jdk/src/share/classes/java/io/PushbackInputStream.java
diffstat 2 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/src/share/classes/java/io/BufferedInputStream.java	Fri Nov 19 13:35:07 2010 +0000
+++ b/jdk/src/share/classes/java/io/BufferedInputStream.java	Fri Nov 19 10:00:08 2010 -0800
@@ -395,7 +395,11 @@
      *                          or an I/O error occurs.
      */
     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;
     }
 
     /**
--- a/jdk/src/share/classes/java/io/PushbackInputStream.java	Fri Nov 19 13:35:07 2010 +0000
+++ b/jdk/src/share/classes/java/io/PushbackInputStream.java	Fri Nov 19 10:00:08 2010 -0800
@@ -273,7 +273,11 @@
      */
     public int available() throws IOException {
         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;
     }
 
     /**