Skip to content

Commit 14b36f8

Browse files
authored
Merge pull request SDWebImage#3505 from dreampiggy/bugfix/cache_nil_key
Protect the disk operation when input key is nil
2 parents a812079 + 8d09564 commit 14b36f8

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

SDWebImage/Core/SDImageCache.m

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,9 @@ - (nullable UIImage *)imageFromDiskCacheForKey:(nullable NSString *)key {
419419
}
420420

421421
- (nullable UIImage *)imageFromDiskCacheForKey:(nullable NSString *)key options:(SDImageCacheOptions)options context:(nullable SDWebImageContext *)context {
422+
if (!key) {
423+
return nil;
424+
}
422425
NSData *data = [self diskImageDataForKey:key];
423426
UIImage *diskImage = [self diskImageForKey:key data:data options:options context:context];
424427

@@ -507,6 +510,9 @@ - (nullable NSData *)diskImageDataBySearchingAllPathsForKey:(nullable NSString *
507510
}
508511

509512
- (nullable UIImage *)diskImageForKey:(nullable NSString *)key {
513+
if (!key) {
514+
return nil;
515+
}
510516
NSData *data = [self diskImageDataForKey:key];
511517
return [self diskImageForKey:key data:data options:0 context:nil];
512518
}
@@ -521,7 +527,7 @@ - (nullable UIImage *)diskImageForKey:(nullable NSString *)key data:(nullable NS
521527
}
522528

523529
- (void)_unarchiveObjectWithImage:(UIImage *)image forKey:(NSString *)key {
524-
if (!image) {
530+
if (!image || !key) {
525531
return;
526532
}
527533
// Check extended data
@@ -721,7 +727,7 @@ - (void)removeImageForKey:(nullable NSString *)key fromDisk:(BOOL)fromDisk withC
721727
}
722728

723729
- (void)removeImageForKey:(nullable NSString *)key fromMemory:(BOOL)fromMemory fromDisk:(BOOL)fromDisk withCompletion:(nullable SDWebImageNoParamsBlock)completion {
724-
if (key == nil) {
730+
if (!key) {
725731
return;
726732
}
727733

0 commit comments

Comments
 (0)