alexiscreuzot / SwiftyGif

High performance GIF engine
MIT License
2.02k stars 212 forks source link

Be much more robust against malformed gifs and user error. #31

Closed misterbunnyworth closed 7 years ago

misterbunnyworth commented 7 years ago

We were experiencing app crashes due to user-uploaded content, so we wanted to guard against unexpected results from Core Image. The primary bug we encountered was that delayTimes() expected the GIF dictionary to always be present, which is not necessarily true -- it's valid to gifs with no metadata properties, and they exist in the wild.

We also took the opportunity to make everything a bit more guarded, so that for instance calling isPlaying on an arbitrary UIImageView won't crash the app, even if the view in question doesn't host an animated GIF.

The general approach was to be extra paranoid about nil values, and to eliminate ! suffixes wherever we could. The result works with our test images that could cause crashes, and well-formed images continue to work.

However, there are some slight API incompatibilities: properties that return associated objects are now marked as optional, so calling them when an image isn't animated will not crash the app.