JDK-8074954 : ImageInputStreamImpl.readShort/readInt do not behave correctly at EOF
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.imageio
  • Affected Version: 7u40,8u40,9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2015-03-11
  • Updated: 2015-09-29
  • Resolved: 2015-03-23
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8 JDK 9
7u85Fixed 8u60Fixed 9 b59Fixed
Description
The readShort and readInt methods call:

if (read(byteBuf, 0, 2) < 0) {
   throw new EOFException();
}

and

if (read(byteBuf, 0, 4) < 0) {
   throw new EOFException();
}

respectively. However, for readShort, if only a single byte is left, or for
readInt, if less than 4 bytes are left, the code that follows will use
incorrect values from the byteBuf array.
Comments
We have to ensure that required number of bytes has been successfully read. Supplied regression test demonstrates the problem. http://cr.openjdk.java.net/~bae/8074954/9/webrev.00/
20-03-2015