bumptech / glide

An image loading and caching library for Android focused on smooth scrolling
https://bumptech.github.io/glide/
Other
34.6k stars 6.12k forks source link

Failed to load a gif. #4971

Open ZouYongpeng opened 1 year ago

ZouYongpeng commented 1 year ago

I found Glide cannot load this gif at all android devices, like Pixel 3 XL. bug_2

My code:

build.gradle

dependencies {
    // Glide
    implementation 'com.github.bumptech.glide:glide:4.13.2'
}

MainActivity

private fun loadGif() {
        Glide.with(this)
            .asGif()
            .load(R.drawable.bug_2)
            .listener(loadGifListener)
            .into(imageView)
    }

private val loadGifListener: RequestListener<GifDrawable> = object : RequestListener<GifDrawable> {

        override fun onLoadFailed(
            e: GlideException?,
            model: Any?,
            target: Target<GifDrawable>?,
            isFirstResource: Boolean
        ): Boolean {
            Log.d(TAG, "gif onLoadFailed: ")
            return false
        }

        override fun onResourceReady(
            resource: GifDrawable?,
            model: Any?,
            target: Target<GifDrawable>?,
            dataSource: DataSource?,
            isFirstResource: Boolean
        ): Boolean {
            Log.d(TAG, "gif onResourceReady: ")
            return false
        }
    }

Error log:

2022-12-14 14:38:21.780 9694-9694/com.zyp.glidedemo W/Glide: Load failed for 2131165280 with size [666x1262]
    class com.bumptech.glide.load.engine.GlideException: Failed to load resource
      Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{AssetInputStream->GifDrawable->GifDrawable}, LOCAL
        Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{AssetInputStream->GifDrawable->GifDrawable}
2022-12-14 14:38:21.780 9694-9694/com.zyp.glidedemo D/GlideDemo: gif onLoadFailed: 

My analysis: I think this Gif format is special and Glide can't parse it successfully. glide_bug_1 glide_bug_2

ZouYongpeng commented 1 year ago

I also found another problematic gif file.

The log is as follows W/Glide: Load failed for [content://com.oplus.wallpapers.fileProvider/gallery_pictures/storage/emulated/0/DCIM/Camera/gif_load_error_9e_05_04_00_3b.gif] with dimensions [382x720] class com.bumptech.glide.load.engine.GlideException: Failed to load resource Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{AutoCloseInputStream->GifDrawable->GifDrawable}, LOCAL Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{AutoCloseInputStream->GifDrawable->GifDrawable}

Through breakpoint debugging, I found that GifHeaderParser.read() threw an exception when parsing the file, resulting in a status of STATUS_FORMAT_ERROR.

The exception code is currByte = rawData.get() & MASK_INT_LOWEST_BYTE; I think it may be that BufferUnderflowException is thrown when the rawData.get() method is executed. Does Glide have a plan to ensure that the effective data length in ByteBuffer is sufficient or perform exception handling?

Does Glide have any format requirements for Gif files? This Gif file starts with "47 49 46 38 39 61" and ends with "3b". I can't determine whether there is a problem with the Gif file format, after all, it can be displayed normally on other apps.

What frustrates me is that I can't upload the problematic gif file and the screenshot of the breakpoint debugging code.

WoKee commented 4 weeks ago

Failed DecodePath{AssetInputStream->GifDrawable->GifDrawable}

Has it been resolved? I also encountered this problem