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

Crashes with invalid GIF data #18

Closed
qvik opened this issue Dec 9, 2015 · 4 comments
Closed

Crashes with invalid GIF data #18

qvik opened this issue Dec 9, 2015 · 4 comments
Labels

Comments

@qvik
Copy link

qvik commented Dec 9, 2015

Hi, trying to load invalid data as a GIF crashes this code with EXC_BAD_ACCESS. This is due to the unsafe code in delayForImageAtIndex(). Proper checks should be in place and the UIImage.gifWithData() should throw / return nil if invalid data was handed in.

As a quick hack, the following is how I made this 'work' (= not crash):

    class func delayForImageAtIndex(index: Int, source: CGImageSource!) -> Double {
        var delay = 0.1

        guard let cfProperties = CGImageSourceCopyPropertiesAtIndex(source, index, nil) as? NSDictionary,
            gifProperties = cfProperties[kCGImagePropertyGIFDictionary as NSString] as? NSDictionary else {
                return delay
        }

        var delayTime = gifProperties[kCGImagePropertyGIFUnclampedDelayTime as NSString]

        if delayTime?.doubleValue == 0.0 {
            delayTime = gifProperties[kCGImagePropertyGIFDelayTime as NSString]
        }

        if let delayTime = delayTime {
            delay = delayTime.doubleValue
        }

        if delay < 0.1 {
            delay = 0.1 // Make sure they're not too fast
        }

        return delay
    }

Also, building for the device, I get the linker error:

ld: framework not found SwiftGifOrigin for architecture arm64
  • Matti
@bahlo bahlo added the bug label Jan 28, 2016
@bahlo
Copy link
Member

bahlo commented Jan 28, 2016

Thank you for the information and sample code! 👍

@bahlo
Copy link
Member

bahlo commented Jan 28, 2016

I tested your code, but the tests are failing due to failed access of cfProperties.
I would be very grateful if you could fix this error and create a PR? 💯

@qvik
Copy link
Author

qvik commented Mar 18, 2016

What do you mean 'failed access of cfProperties'? The code I posted compiles & executes without errors on Xcode 7.x build?

It is fairly crucial for our system that the app does not crash when possibly handed a broken .gif, so having this fix is a must.

-Matti

@bahlo
Copy link
Member

bahlo commented Aug 22, 2016

Closed via #25, feel free to reopen if the issue persists.

@bahlo bahlo closed this as completed Aug 22, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

1 participant