< prev index next >

src/java.base/share/classes/java/io/StringBufferInputStream.java

Print this page
rev 15329 : imported patch 8163518-Integer-overflow-in-StringBufferInputStream-read-byte-int-int

@@ -116,12 +116,14 @@
             throw new IndexOutOfBoundsException();
         }
         if (pos >= count) {
             return -1;
         }
-        if (pos + len > count) {
-            len = count - pos;
+
+        int avail = count - pos;
+        if (len > avail) {
+            len = avail;
         }
         if (len <= 0) {
             return 0;
         }
         String  s = buffer;
< prev index next >