Yamipa

Yamipa

3.7k Downloads

Exception when reading GIFs without End-of-Information code

Andreassenemyr opened this issue ยท 3 comments

commented

5de30a61ca52c6010e571b43f9bfcc3e

commented

Hi, @Andreassenemyr!

Could you provide the GIF file that's giving you the error?

commented

I've more info on this!

Turns out it's not Yamipa's fault but a an issue with the GIFImageReader class that comes with Java, which expects every frame in a GIF file to end with a "End of Information code" as the GIF89a spec says. Some ultra-compressed GIF files ignore the spec and skip these codes, so most image decoders/readers are a bit lax and keep rendering the file even without the EOF codes. Unfortunately, that's not the case with JDK.

The three main solutions we have are:

  • Implement an alternative GIF decoder from scratch (no way I'm doing that, rather watch paint dry)
  • Use another existing GIF decoder (like Apache Commons Imaging) and bundle it Yamipa
  • Provide Yamipa with GIF files compliant with the spec

I'm also not a fan of adding more code to Yamipa and making the library more complicated and larger in size, so the second option is discarded. I think the best option is the last one, just use an online tool like ezgif.com to re-encode GIF files and feed that to Yamipa.

I'm closing this for now, if somebody knows of a quick fix let me know! :)

commented

Can reproduce the issue with the GIF file provided in #33. Thanks, @GodModed!

Building Yamipa from the develop branch now gives a different exception:

javax.imageio.IIOException: I/O error reading image!
        at com.sun.imageio.plugins.gif.GIFImageReader.read(GIFImageReader.java:1046) ~[?:?]
        at javax.imageio.ImageReader.read(ImageReader.java:938) ~[?:?]
        at io.josemmo.bukkit.plugin.storage.ImageFile.renderImages(ImageFile.java:131) ~[YamipaPlugin.jar:?]
        at io.josemmo.bukkit.plugin.storage.ImageFile.getMapsAndSubscribe(ImageFile.java:263) ~[YamipaPlugin.jar:?]
        at io.josemmo.bukkit.plugin.storage.ImageFile.getMapsAndSubscribe(ImageFile.java:213) ~[YamipaPlugin.jar:?]
        at io.josemmo.bukkit.plugin.renderer.FakeImage.load(FakeImage.java:342) ~[YamipaPlugin.jar:?]
        at io.josemmo.bukkit.plugin.renderer.FakeImage.lambda$spawn$12(FakeImage.java:378) ~[YamipaPlugin.jar:?]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) ~[?:?]
        at java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[?:?]
        at java.lang.Thread.run(Thread.java:833) ~[?:?]
Caused by: javax.imageio.IIOException: Code buffer limit reached, no End of Image tag present, possibly data is corrupted.
        at com.sun.imageio.plugins.gif.GIFImageReader.read(GIFImageReader.java:1011) ~[?:?]
        ... 12 more