Skip to content
This repository has been archived by the owner on Jan 14, 2021. It is now read-only.

Fix crash due to non-standard GIF in case of no value for kCGImagePro… #25

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions SwiftGif.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
1419B38F194EFC11005DF6D0 /* GifTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1419B378194EFBE7005DF6D0 /* GifTests.swift */; };
1419B390194EFC15005DF6D0 /* test.gif in Resources */ = {isa = PBXBuildFile; fileRef = 1419B379194EFBE7005DF6D0 /* test.gif */; };
1482D73B194EFCF10038192B /* UIImage+Gif.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1419B37D194EFBFD005DF6D0 /* UIImage+Gif.swift */; };
FB57A0641CA41C2400065109 /* non_standard_gif.gif in Resources */ = {isa = PBXBuildFile; fileRef = FB57A0631CA41C2400065109 /* non_standard_gif.gif */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -41,6 +42,7 @@
1482D739194EFCE00038192B /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
14A76438194EFBB800A74B1F /* SwiftGif.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SwiftGif.app; sourceTree = BUILT_PRODUCTS_DIR; };
14A76445194EFBB800A74B1F /* SwiftGifTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftGifTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
FB57A0631CA41C2400065109 /* non_standard_gif.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = non_standard_gif.gif; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -87,6 +89,7 @@
1419B381194EFBFD005DF6D0 /* Images.xcassets */,
1419B37F194EFBFD005DF6D0 /* adventure-time.gif */,
1419B383194EFBFD005DF6D0 /* jeremy.gif */,
FB57A0631CA41C2400065109 /* non_standard_gif.gif */,
1419B382194EFBFD005DF6D0 /* Info.plist */,
);
path = SwiftGifDemo;
Expand Down Expand Up @@ -191,6 +194,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
FB57A0641CA41C2400065109 /* non_standard_gif.gif in Resources */,
1419B38D194EFBFD005DF6D0 /* jeremy.gif in Resources */,
1419B38B194EFBFD005DF6D0 /* Images.xcassets in Resources */,
1419B389194EFBFD005DF6D0 /* adventure-time.gif in Resources */,
Expand Down
10 changes: 6 additions & 4 deletions SwiftGifCommon/UIImage+Gif.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ extension UIImage {

// Get dictionaries
let cfProperties = CGImageSourceCopyPropertiesAtIndex(source, index, nil)
let gifProperties: CFDictionaryRef = unsafeBitCast(
CFDictionaryGetValue(cfProperties,
unsafeAddressOf(kCGImagePropertyGIFDictionary)),
CFDictionary.self)
let gifPropertiesPointer = UnsafeMutablePointer<UnsafePointer<Void>>.alloc(0)
if CFDictionaryGetValueIfPresent(cfProperties, unsafeAddressOf(kCGImagePropertyGIFDictionary), gifPropertiesPointer) == false {
return delay
}

let gifProperties:CFDictionaryRef = unsafeBitCast(gifPropertiesPointer.memory, CFDictionary.self)

// Get delay time
var delayObject: AnyObject = unsafeBitCast(
Expand Down
Binary file added SwiftGifDemo/non_standard_gif.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.