From 8a034a403b2f117b5ad5e7f149b2b25f3abe313f Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Sun, 21 Jan 2018 23:43:48 +0800 Subject: [PATCH] Add protect to some Core Graphics methods --- SDWebImage/SDWebImageGIFCoder.m | 12 ++++-------- SDWebImage/SDWebImageWebPCoder.m | 3 +++ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/SDWebImage/SDWebImageGIFCoder.m b/SDWebImage/SDWebImageGIFCoder.m index 8fe17ed6..e63afa04 100644 --- a/SDWebImage/SDWebImageGIFCoder.m +++ b/SDWebImage/SDWebImageGIFCoder.m @@ -58,14 +58,7 @@ } float duration = [self sd_frameDurationAtIndex:i source:source]; -#if SD_WATCH - CGFloat scale = 1; - scale = [WKInterfaceDevice currentDevice].screenScale; -#elif SD_UIKIT - CGFloat scale = 1; - scale = [UIScreen mainScreen].scale; -#endif - UIImage *image = [[UIImage alloc] initWithCGImage:imageRef scale:scale orientation:UIImageOrientationUp]; + UIImage *image = [[UIImage alloc] initWithCGImage:imageRef]; CGImageRelease(imageRef); SDWebImageFrame *frame = [SDWebImageFrame frameWithImage:image duration:duration]; @@ -95,6 +88,9 @@ - (float)sd_frameDurationAtIndex:(NSUInteger)index source:(CGImageSourceRef)source { float frameDuration = 0.1f; CFDictionaryRef cfFrameProperties = CGImageSourceCopyPropertiesAtIndex(source, index, nil); + if (!cfFrameProperties) { + return frameDuration; + } NSDictionary *frameProperties = (__bridge NSDictionary *)cfFrameProperties; NSDictionary *gifProperties = frameProperties[(NSString *)kCGImagePropertyGIFDictionary]; diff --git a/SDWebImage/SDWebImageWebPCoder.m b/SDWebImage/SDWebImageWebPCoder.m index 63cbc6a2..5bffefeb 100644 --- a/SDWebImage/SDWebImageWebPCoder.m +++ b/SDWebImage/SDWebImageWebPCoder.m @@ -394,6 +394,9 @@ size_t bytesPerRow = CGImageGetBytesPerRow(imageRef); CGDataProviderRef dataProvider = CGImageGetDataProvider(imageRef); + if (!dataProvider) { + return nil; + } CFDataRef dataRef = CGDataProviderCopyData(dataProvider); uint8_t *rgba = (uint8_t *)CFDataGetBytePtr(dataRef);