launchdarkly / ios-client-sdk

LaunchDarkly Client-side SDK for iOS (Swift and Obj-C)
https://docs.launchdarkly.com/sdk/client-side/ios
Other
69 stars 84 forks source link

Stack overflow when comparing [String:Any]? nil value with nil #197

Closed lietusme closed 4 years ago

lietusme commented 4 years ago

Describe the bug Crashes with stack overflow when comparing optional nil value to nil. Comparison executes LD extension for operator ==. Does not crash if optional value is set.

Similar to https://github.com/launchdarkly/ios-client-sdk/issues/186

To reproduce Sample code, crashes on if parameters == nil

class Crash {
    static func test(parameters: [String: Any]? = nil) {
        if parameters == nil {
            print("Yes it's nil")
        }
    }
}

Reproduce crash:

Crash.test()

Works fine:

Crash.test(parameters:["Foo":"Boo"])

Comparison overflows within this LD extension on return rhs == nil:

extension Optional where Wrapped == [String: Any] {
    public static func == (lhs: [String: Any]?, rhs: [String: Any]?) -> Bool {
        guard let lhs = lhs
        else {
            return rhs == nil
        }
        guard let rhs = rhs
        else {
            return false
        }
        return lhs.isEqual(to: rhs)
    }
    public static func != (lhs: [String: Any]?, rhs: [String: Any]?) -> Bool {
        return !(lhs == rhs)
    }
}

Expected behavior Return true because optional is nil.

SDK version 4.2.0

Language version, developer tools Swift 5.0, CocoaPods, XCode 11.0

OS/platform iOS 13 SDK

bwoskow-ld commented 4 years ago

Thanks for reporting this. We should be able to include a fix for this bug in the next SDK release.

lietusme commented 4 years ago

Thanks. Any estimates when next release can be expected?

bwoskow-ld commented 4 years ago

We're aiming to have a release out by the end of this week.

torchhound commented 4 years ago

Hi @lietusme this is fixed in version 4.2.1, thanks for reporting this issue!