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

InputStream.read(buf, off, len) contains extra comparisons in bounds checking

XMLWordPrintable

    • b31
    • x86
    • solaris_8



      Name: gm110360 Date: 08/05/2003


      FULL PRODUCT VERSION :
      1.4.0-beta2 on Tru64, but it's a SOURCE CODE problem

      FULL OPERATING SYSTEM VERSION : Source code


      A DESCRIPTION OF THE PROBLEM :
      In InputStream.read, there's a comparison for array bounds:

      else if ((off < 0) || (off > b.length) || (len < 0) ||
                ((off + len) > b.length) || ((off + len) < 0)) {

      It's sufficient to just test for:

       off < 0 || len < 0 || (off + len) > b.length

      If off > b.length, and len >= 0, then (off + len) must be >
      b.length.
      If (off + len) < 0, then one of off or len must be < 0.

      One other little detail, the JavaDoc for that method
      doesn't mention the ArrayIndexOutOfBoundsException.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Check the code
      2.
      3.

      EXPECTED VERSUS ACTUAL BEHAVIOR :

      I found this in 1.3 and 1.4.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      CUSTOMER WORKAROUND :

      The only impact if a couple of cycles on each call to read
      ().
      (Incident Review ID: 165243)
      ======================================================================

            sjiang Shanliang Jiang (Inactive)
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: