-
Bug
-
Resolution: Fixed
-
P2
-
1.4.0
-
beta
-
generic
-
generic
Name: boT120536 Date: 03/06/2001
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
Java HotSpot(TM) Client VM (build 1.3.0, mixed mode)
[ This bug is in EA2, however the EA bug report
page has options for submitting only EA1 IIO
bug reports. ]
Flushing or closing a MemoryCacheImageOutputStream invokes
MemoryCache.writeToStream(), where this code (line 114
in MemoryCache.java) throws an IndexOutOfBounds:
if ((pos >= length) || (pos+len>=length)) {
throw new IndexOutOfBoundsException("Argument out of cache");
It's an off-by-one error: the >= tests on the first
line should be > tests.
Example Code
// Compile and run with:
// javac -classpath .:imageio-1_0-ea2/imageio.jar MemoryCacheLengthBug.java
// java -classpath .:imageio-1_0-ea2/imageio.jar MemoryCacheLengthBug
// Produces:
// java.lang.IndexOutOfBoundsException: Argument out of cache
// at javax.imageio.stream.MemoryCache.writeToStream(MemoryCache.java:115)
// at javax.imageio.stream.MemoryCacheImageOutputStream.flushBefore(MemoryCacheImageOutputStream.java:127)
// at javax.imageio.stream.ImageInputStreamImpl.flush(ImageInputStreamImpl.java:714)
// at MemoryCacheLengthBug.main(MemoryCacheLengthBug.java:16)
import java.io.FileOutputStream;
import javax.imageio.stream.MemoryCacheImageOutputStream;
class MemoryCacheLengthBug {
static public void main( String [] args ) {
try {
MemoryCacheImageOutputStream stream =
new MemoryCacheImageOutputStream( new FileOutputStream( "test.txt" ) );
stream.write( 0 ); // or write anything, for that matter
stream.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
}
(Review ID: 115807)
======================================================================
- relates to
-
JDK-4417672 MemoryCacheImageOutputStream ignores stream position
-
- Resolved
-