[OpenJDK 2D-Dev] <AWT Dev> [rfc]Stream doesn't reset mark in finally

Alexander Scherbatiy alexandr.scherbatiy at oracle.com
Mon Nov 9 12:45:48 UTC 2015


On 11/7/2015 11:38 AM, Jiri Vanek wrote:
> Hello!
>
> Looking to imageIO.java (if this is bad thread, please redirect me!) 

     2d-dev alias should be also the right place to ask image related 
questions in AWT.

    Thanks,
    Alexandr.

> when reading images
> http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/share/classes/javax/imageio/ImageIO.java#l543 
>
> and ending at:
>
>                 // Perform mark/reset as a defensive measure
>                 // even though plug-ins are supposed to take
>                 // care of it.
>                 boolean canDecode = false;
>                 if (stream != null) {
>                     stream.mark();
>                 }
>                 canDecode = spi.canDecodeInput(input);
>                 if (stream != null) {
>                     stream.reset();
>                 }
>                 return canDecode;
>
> I'm wondering, why  stream.reset(); is not in finaly  block:
>
> // Perform mark/reset as a defensive measure
> // even though plug-ins are supposed to take
> // care of it.
> boolean canDecode = false;
> if (stream != null) {
> stream.mark();
> }
> try{
>     canDecode = spi.canDecodeInput(input);
> } finally {
>     if (stream != null) {
>         stream.reset();
>     }
> }
> return canDecode;
>
>
> Eg png and bmp decoders can are throwing IIOException when header is 
> corrutped. That pretty definitely sure killer of  stream mark stacks.
> You yourselves write  : //Perform mark/reset as a defensive measure 
> even though plug-ins are supposed to take care of it.
> So if densive, then try/finaly please.
>
> I did not check if this changed in 9 but if not....Please. This is 
> makig work on custom image plugins, for image formats which just wraps 
> another bmp/png and are expecting corrupted headers preatty hards.
>
>
> J.




More information about the 2d-dev mailing list