Menu

#4 ICODecoder fails to read the image from a jar file

open
nobody
None
5
2015-02-06
2013-03-12
Trejkaz
No

We have icons checked into our jar file. Reading such an icon using the simplest code I expect to work:

try (InputStream stream = resource.openStream()) {
icos = ICODecoder.readExt(stream);
}

results in an IOException at present.

A cursory look at the code reveals several basic bugs - for instance, instead of calling read(byte[]) in a loop, it is called once and then any result other than the expected length results in an exception.

However, due to another bug which I raised separately, it is impossible to know what the actual error was.

Discussion

  • Ian

    Ian - 2013-05-08

    Would it be possible for you to post an example jar file that can be read to produce the problem?

     
  • Schmidor

    Schmidor - 2015-02-02

    I suppose this happens on large layers. On some icons I'm using this occurs on layer #3 which is 256x256 pixels in size. It seems that the Ressource InputStream.read Method doesn't fill the byte array in one turn.

    Changing src\net\sf\image4j\codec\ico\ICODecoder.java
    lines 230-233:

          int count = in.read(pngData);
          if (count != pngData.length) {
            throw new IOException("Unable to read image #"+i+" - incomplete PNG compressed data");
          }
    

    to:

          int read = 0;
          int count = 0;
          while(count > -1 && (pngData.length - read) > 0){
            count = in.read(pngData, read, pngData.length - read);
            read += count;
          }
          if (read != pngData.length) {
            throw new IOException("Unable to read image #"+i+" - incomplete PNG compressed data");
          }
    

    fixes that in my case.

     
  • Ian

    Ian - 2015-02-06

    This problem should now be fixed.
    Latest sources are now available at https://github.com/imcdonagh/image4j.

     

Log in to post a comment.

MongoDB Logo MongoDB