Crash at SDAnimatedImage initWithData:scale:options
New Issue Checklist
- [ x] I have read and understood the CONTRIBUTING guide
- [ x] I have read the Documentation
- [ x] I have searched for a similar issue in the project and found none
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)
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?
`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`
Still seeing the problem
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
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.
Any progress about this? The issue is still occurring in the latest version.
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.
Is the issue resolved in latest version of SDWebImage(5.15.0)? Please confirm
Seems OOM issue. We can add a @try but this still cause the image loading faild.
Well, I think a a failed image is way better than a crash. Might be a good idea for a temporary fix?
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 no, we haven't. This issue is by far our biggest crash, with more than 35K crashes per week.
Thanks for the reply @afterxleep . What is the version you are using?
- SDWebImage (= 5.13.4)
- SDWebImageWebPCoder (= 0.9.1)
Decide to simply remove this line to check.

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.
Thanks @dreampiggy we'll try that and see if it helps.-
Fixed in 5.15.1