From 2a19d9c36c318f6ee81a5b902f10963967c6c155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=92=9F=E9=93=BF?= Date: Wed, 14 Aug 2024 15:01:46 +0800 Subject: [PATCH] fix a crash bug when image url is unavailable --- SDWebImage/Core/SDDiskCache.m | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/SDWebImage/Core/SDDiskCache.m b/SDWebImage/Core/SDDiskCache.m index 82eb0d6b..28946f90 100644 --- a/SDWebImage/Core/SDDiskCache.m +++ b/SDWebImage/Core/SDDiskCache.m @@ -64,6 +64,11 @@ static NSString * const SDDiskCacheExtendedAttributeName = @"com.hackemist.SDDis - (NSData *)dataForKey:(NSString *)key { NSParameterAssert(key); NSString *filePath = [self cachePathForKey:key]; + // if filePath is nil or (null),framework will crash with this: + // Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[_NSPlaceholderData initWithContentsOfFile:options:maxLength:error:]: nil file argument' + if (filePath == nil || [@"(null)" isEqualToString: filePath]) { + return nil; + } NSData *data = [NSData dataWithContentsOfFile:filePath options:self.config.diskCacheReadingOptions error:nil]; if (data) { return data;