Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4105384

java.io.PipedInputStream.read fails when off + len > Integer.MAX_VALUE

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.2.0
    • core-libs
    • sparc
    • solaris_2.5



      Name: saC57035 Date: 01/21/98


      The java.io.PipedInputStream read(byte b[], int off, int len) may not throw
      IndexOutOfBoundsException in case of off or len out of bounds. That is caused
      by overflow which occurs when off + len exceed Integer.MAX_VALUE.

      Actually this bug is a follow up for bugs 1266817 and 1266818. They were fixed
      in 1.1, however the fix happened to be incomplete.

      This bug causes the following JCK test to fail:
      api/java_io/PipedInputStream/manual.html#Read


      Below is the test demonstrating the bug:
      ----------- ClassTest.java--------------------
      import java.io.*;

      public class Test5 {

         public static void main( String[] argv ) {
           PipedOutputStream os = new PipedOutputStream();
           PipedInputStream is = new PipedInputStream();
           try {
             is.connect(os);
           } catch(Throwable e) {
             System.out.println("Test failed: unexpected <"+e+"> thrown");
           }
           byte[] b = new byte[10];
           try {
             os.write(101);
             os.close();
             is.read(b,1,Integer.MAX_VALUE);
             System.out.println("Test failed: IndexOutOfBoundsException expected");

           } catch(IndexOutOfBoundsException e) {
             try {
               int a = is.read();
               if (a==101)
                 System.out.println("Test passed: IndexOutOfBoundsException thrown");
               else
                 System.out.println("Test failed: unexpected reading performed");
             } catch(IOException e1) {
               System.out.println("Test failed: unexpected <"+e1+"> thrown");
             }
           } catch(Throwable e) {
             System.out.println("Test failed: unexpected <"+e+"> thrown");
           }
         }
      }
      ------ Output of the test --------
      Test failed: IndexOutOfBoundsException expected

      ======================================================================

            zlisunw Zhenghua Li (Inactive)
            savzan Stanislav Avzan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: