SDWebImage icon indicating copy to clipboard operation
SDWebImage copied to clipboard

Crash at SDAnimatedImage initWithData:scale:options

Open afterxleep opened this issue 4 years ago • 7 comments

New Issue Checklist

Issue Info

Info Value
Platform Name ios
Platform Version 14.x / 15.x
SDWebImage Version 5.12
Integration Method cocoapods
Xcode Version Xcode 12 / Xcode 13
Repro rate 0.5% - 1%

Issue Description and Steps

We are seeing a significant increase in volume for OOM crashes while initializing animated images. Our stack uses mostly webp images.

Any ideas?

Fatal Exception: NSInvalidArgumentException
*** NSAllocateMemoryPages(1038998) failed

Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0x129dc0 __exceptionPreprocess
1  libobjc.A.dylib                0x287a8 objc_exception_throw
2  Foundation                     0x13c234 NSZoneMalloc
3  Foundation                     0xecf4 -[_NSPlaceholderData initWithBytes:length:copy:deallocator:]
4  Tumblr                         0x128118c -[SDAnimatedImage initWithData:scale:options:] + 127 (SDAnimatedImage.m:127)
5  Tumblr                         0x12969cc SDImageLoaderDecodeImageData + 80 (SDImageLoader.m:80)
6  Tumblr                         0x12a0fcc __70-[SDWebImageDownloaderOperation URLSession:task:didCompleteWithError:]_block_invoke.244 + 528 (SDWebImageDownloaderOperation.m:528)
7  Foundation                     0x132f88 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__
8  Foundation                     0x20628 -[NSBlockOperation main]
9  Foundation                     0x1353b0 __NSOPERATION_IS_INVOKING_MAIN__
10 Foundation                     0x202b0 -[NSOperation start]
11 Foundation                     0x135e54 __NSOPERATIONQUEUE_IS_STARTING_AN_OPERATION__
12 Foundation                     0x1358e0 __NSOQSchedule_f
13 libdispatch.dylib              0x13484 _dispatch_block_async_invoke2
14 libdispatch.dylib              0x481c _dispatch_client_callout
15 libdispatch.dylib              0x7cf4 _dispatch_continuation_pop
16 libdispatch.dylib              0x7440 _dispatch_async_redirect_invoke
17 libdispatch.dylib              0x15fe0 _dispatch_root_queue_drain
18 libdispatch.dylib              0x167d8 _dispatch_worker_thread2
19 libsystem_pthread.dylib        0x3768 (Missing)
20 libsystem_pthread.dylib        0xa74c (Missing)

afterxleep avatar Nov 18 '21 10:11 afterxleep

Experience the same problem here with the ".gif" images. Did you find a way to fix it or what is the reason of the problem?

rk-helper avatar Dec 12 '21 10:12 rk-helper

`Fatal Exception: NSInvalidArgumentException

0 CoreFoundation 0x12586c __exceptionPreprocess 1 libobjc.A.dylib 0x6c50 objc_exception_throw 2 Foundation 0x13caf8 NSZoneMalloc 3 Foundation 0xee24 -[_NSPlaceholderData initWithBytes:length:copy:deallocator:] 4 Tools 0x120d64 -[SDAnimatedImage initWithData:scale:options:] + 127 (SDAnimatedImage.m:127) 5 Tools 0x136498 SDImageLoaderDecodeImageData + 80 (SDImageLoader.m:80) 6 Tools 0x140b54 __70-[SDWebImageDownloaderOperation URLSession:task:didCompleteWithError:]_block_invoke.234 + 498 (SDWebImageDownloaderOperation.m:498) 7 Foundation 0x133850 NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK 8 Foundation 0x20740 -[NSBlockOperation main] 9 Foundation 0x135ca4 NSOPERATION_IS_INVOKING_MAIN 10 Foundation 0x203c8 -[NSOperation start] 11 Foundation 0x13674c NSOPERATIONQUEUE_IS_STARTING_AN_OPERATION 12 Foundation 0x1361d4 __NSOQSchedule_f 13 libdispatch.dylib 0x11fb8 _dispatch_block_async_invoke2 14 libdispatch.dylib 0x3db0 _dispatch_client_callout 15 libdispatch.dylib 0x712c _dispatch_continuation_pop 16 libdispatch.dylib 0x6854 _dispatch_async_redirect_invoke 17 libdispatch.dylib 0x1493c _dispatch_root_queue_drain 18 libdispatch.dylib 0x15120 _dispatch_worker_thread2 19 libsystem_pthread.dylib 0x37d8 _pthread_wqthread 20 libsystem_pthread.dylib 0xa76c start_wqthread`

rk-helper avatar Dec 12 '21 10:12 rk-helper

Still seeing the problem

afterxleep avatar Feb 04 '22 01:02 afterxleep

Also #3319 : Not sure if it's related to

- (instancetype)initWithData:(NSData *)data scale:(CGFloat)scale options:(SDImageCoderOptions *)options {
    if (!data || data.length == 0) {
        return nil;
    }
    data = [data copy]; // avoid mutable data

danielebogo avatar Feb 08 '22 11:02 danielebogo

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions.

stale[bot] avatar Apr 17 '22 06:04 stale[bot]

Any progress about this? The issue is still occurring in the latest version.

afterxleep avatar Apr 17 '22 08:04 afterxleep

Same issue, i just wanted to understand whether this issue is related to SDWebImage or not. I am using a react native library which internally uses SDWebImage and we are seeing crashes on iOS devices only.

vivekverma1993 avatar Apr 20 '22 04:04 vivekverma1993

Is the issue resolved in latest version of SDWebImage(5.15.0)? Please confirm

albindb92 avatar Feb 06 '23 11:02 albindb92

Seems OOM issue. We can add a @try but this still cause the image loading faild.

dreampiggy avatar Feb 06 '23 12:02 dreampiggy

Well, I think a a failed image is way better than a crash. Might be a good idea for a temporary fix?

afterxleep avatar Feb 06 '23 12:02 afterxleep

Hi @afterxleep, were you able to resolve the issue? We are also facing a large number of crashes for the below version: SDWebImage ~> 5.11.1' SDWebImageWebPCoder ~> 0.8.4

albindb92 avatar Feb 06 '23 12:02 albindb92

@albindb92 no, we haven't. This issue is by far our biggest crash, with more than 35K crashes per week.

afterxleep avatar Feb 06 '23 12:02 afterxleep

Thanks for the reply @afterxleep . What is the version you are using?

albindb92 avatar Feb 06 '23 13:02 albindb92

  • SDWebImage (= 5.13.4)
  • SDWebImageWebPCoder (= 0.9.1)

afterxleep avatar Feb 06 '23 13:02 afterxleep

Decide to simply remove this line to check. 截屏2023-02-06 21 09 46

The initWithAnimatedImageData: in coder protocol already handle mutable data by their own impl. So it's no use to copy here.

For example, libwebp can allows dummy trunking for bytes, so it's safe to pass NSMutableData to it.

dreampiggy avatar Feb 06 '23 13:02 dreampiggy

Thanks @dreampiggy we'll try that and see if it helps.-

afterxleep avatar Feb 06 '23 13:02 afterxleep

Fixed in 5.15.1

dreampiggy avatar Feb 06 '23 14:02 dreampiggy