APNG4Android: width and height must be > 0

New Issue Checklist

  • [X ] I have searched for a similar issue in the project and found none

Issue Info

Info Value
Device Info e.g. ZTE BLADE V9, and most Android 9 to lower
System Version e.g. 7 to 9
APNG4Android Library Version e.g. 2.17
Repro rate e.g. all the time (100%)
Repro with our demo project e.g. does it happen with our demo project?
Demo project link none

Issue Description and Steps

Im trying to solve error and to pass error with Try Catch without success, i have hours and days of debugging to check if app is passing a null image but not, it only happens on old Android devices when i load about 30 animated webps in imageviews, on newer version of android is OK.

Fatal Exception: java.lang.IllegalArgumentException: width and height must be > 0 at android.graphics.Bitmap.createBitmap(Bitmap.java:1114) at android.graphics.Bitmap.createBitmap(Bitmap.java:1081) at android.graphics.Bitmap.createBitmap(Bitmap.java:1031) at android.graphics.Bitmap.createBitmap(Bitmap.java:992) at com.github.penfeizhou.animation.decode.FrameSeqDecoder.obtainBitmap(FrameSeqDecoder.java:130) at com.github.penfeizhou.animation.webp.decode.WebPDecoder.renderFrame(WebPDecoder.java:146) at com.github.penfeizhou.animation.decode.FrameSeqDecoder.step(FrameSeqDecoder.java:505) at com.github.penfeizhou.animation.decode.FrameSeqDecoder.access$200(FrameSeqDecoder.java:36) at com.github.penfeizhou.animation.decode.FrameSeqDecoder$1.run(FrameSeqDecoder.java:60) at com.github.penfeizhou.animation.decode.FrameSeqDecoder.innerStart(FrameSeqDecoder.java:310) at com.github.penfeizhou.animation.decode.FrameSeqDecoder.access$900(FrameSeqDecoder.java:36) at com.github.penfeizhou.animation.decode.FrameSeqDecoder$9.run(FrameSeqDecoder.java:446) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:240) at android.os.HandlerThread.run(HandlerThread.java:67)

Happens on FrameSeqDecoder.obtainBitmap, i have more than 1000 alerts of errors on Crashlytics.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 41 (15 by maintainers)

Most upvoted comments

Hi again, after heavy testing and debugging the new version, there is still the same problem,

Checking my webp files, i found one that is causing this bug, if webp has a transparent frame or blank frame it causes error width and height must be > 0 even if it has same height and width than next frames: imagen Look at first frame, it are blank frame/transparent frame, if use it in my app, app crashes(only on some phones).

But if i delete blank frame it work like charm in app, so the problem is in some devices blank frames are detected without size. apparently APNG detects the size of frame correctly, but not android.graphics.Bitmap.createBitmap 0x0px when passed to system.

Affected webp, test on your phone this files: https://cdn.noten.in/temp/badwebp.webp ❌ With blank frame https://cdn.noten.in/temp/goodwebp.webp ✔️Edited on EzGif

So how to check if frame is transparent? by size? by color depth? maybe can skip transparent frames.

My app loads dynamically a grid of imageviews, so i cant edit one by one, i have like 125,620 webps on server to load.

1870 user phones has same error imagen

When parsing WebP formats, there is no relation to android platform api. And according to webp spec, the width and height cannot be less than 1.Because this is a unsigned value.

Canvas Width Minus One: 24 bits
1-based width of the canvas in pixels. The actual canvas width is '1 + Canvas Width Minus One'
Canvas Height Minus One: 24 bits
1-based height of the canvas in pixels. The actual canvas height is '1 + Canvas Height Minus One'

This could only happen when there is no ANIM Chunk, this library treats it as non animated webp. In this case, it calls platform api to get width and height.

if (!anim) {
            //静态图
            if (!vp8x) {
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inJustDecodeBounds = true;
                BitmapFactory.decodeStream(reader.toInputStream(), null, options);
                canvasWidth = options.outWidth;
                canvasHeight = options.outHeight;
            }
            frames.add(new StillFrame(reader, canvasWidth, canvasHeight));
            this.loopCount = 1;
        }

It’s hosted in mavencentral,you can download it later.

It looks like when system decoding webp file, the options.outWidth or options.outHeight return 0.

if (!anim) {
            if (!vp8x) {
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inJustDecodeBounds = true;
                BitmapFactory.decodeStream(reader.toInputStream(), null, options);
                canvasWidth = options.outWidth;
                canvasHeight = options.outHeight;
            }
            frames.add(new StillFrame(reader, canvasWidth, canvasHeight));
            this.loopCount = 1;
        }

Would you debug and find more information? Here on com.github.penfeizhou.animation.webp.decode.AnimationFrame.java line 32,33

 this.frameWidth = anmfChunk.frameWidth;
 this.frameHeight = anmfChunk.frameHeight;

Set a conditional breakpoint and check if this is a parsing problem. image