harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Xiao-Feng Li" <xiaofeng...@gmail.com>
Subject Re: [classlib][imageio] a potential bug in reading PNG file
Date Wed, 11 Apr 2007 01:50:43 GMT
Will anybody work in this area please have a look at this issue?

Thanks,
xiaofeng

On 4/10/07, chunrong lai <chunronglai@gmail.com> wrote:
> hi, colleagues:
>
>    I met some problem in function canDecodeInput of PNGImageReaderSpi to
> guarantee the reading of  a complete file header.  The code snippet with my
> modification is given below.
>
> //classlib\modules\imageio\src\main\java\org\apache\harmony\x\imageio\plugins\png\PNGImageReaderSpi
>     @Override
>     public boolean canDecodeInput(Object source) throws IOException {
>         ImageInputStream markable = (ImageInputStream) source;
>         markable.mark();
>
>         byte[] signature = new byte[8];
>         markable.seek(0);
>         //markable.read(signature, 0,
> 8);                                             //original code
>         int nBytes =    markable.read(signature, 0,
> 8);                          //my new code
>         if(nBytes != 8) markable.read(signature, nBytes, 8-nBytes);
> //my new code
>         markable.reset();
>
>          // PNG signature: 137 80 78 71 13 10 26 10
>         return  (signature[0] & 0xFF) == 137 &&
>                 (signature[1] & 0xFF) == 80 &&
>                 (signature[2] & 0xFF) == 78 &&
>                 (signature[3] & 0xFF) == 71 &&
>                 (signature[4] & 0xFF) == 13 &&
>                 (signature[5] & 0xFF) == 10 &&
>                 (signature[6] & 0xFF) == 26 &&
>                 (signature[7] & 0xFF) == 10;
>     }
>
>    The potential bug can happen in javax.imageio.ImageIOTest (in classlib
> test).
>
>    The test will fail if the specific image file is checked with JPG format
> before PNG format, but the order in my opinion should not really matter
> between JPGImageReader and PNGImageReader in the iterator. Would someone
> please review this issue and probably fix the bug? Thanks.
>
> -chunrong
>


-- 
http://xiao-feng.blogspot.com

Mime
View raw message