From 1ac74811b198b4066f2c07eb86b0c329b3536def Mon Sep 17 00:00:00 2001 From: James Ide Date: Thu, 26 Feb 2015 07:20:36 -0800 Subject: [PATCH] [Images] Bail out when GIF data is in unexpected format instead of crashing Summary: When the GIF data is not a string nor NSData, `imageSource` is some unknown value set to whatever memory was on the stack. Calling `CGImageSourceGetType` on it has undefined behavior, and if it makes through to the CFRelease (maybe because it is NULL) then CFRelease will crash. This fixes a clang warning. Closes https://github.com/facebook/react-native/pull/77 Github Author: James Ide Test Plan: Imported from GitHub, without a `Test Plan:` line. --- ReactKit/Base/RCTConvert.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ReactKit/Base/RCTConvert.m b/ReactKit/Base/RCTConvert.m index 752d03ced0bde9..ab79cd8617742b 100644 --- a/ReactKit/Base/RCTConvert.m +++ b/ReactKit/Base/RCTConvert.m @@ -446,6 +446,9 @@ + (CAKeyframeAnimation *)GIF:(id)json } imageSource = CGImageSourceCreateWithData((CFDataRef)data, NULL); + } else { + RCTLogMustFix(@"Expected NSString or NSData for GIF, received %@: %@", [json class], json); + return nil; } if (!UTTypeConformsTo(CGImageSourceGetType(imageSource), kUTTypeGIF)) {