launchdarkly / ios-client-sdk

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

Stack overflow when comparing two nil objects of type [String: Any]? #186

Closed AlexWoodblock closed 5 years ago

AlexWoodblock commented 5 years ago

Describe the bug Extension that overrides == operator for Optional<[String:Any]> causes infinite loop with stack overflow when comparing two nil optionals of this type.

To reproduce

  1. Add LaunchDarkly 4.0 to Podfile: pod 'LaunchDarkly', '~>4.0.0'
  2. Run pod install
  3. Add following code anywhere in application
    
    let dict1: [String: Any]? = nil
    let dict2: [String: Any]? = nil

if dict1 == dict2 { print("This will never be printed") }


4. Run the application and make sure the code executes.
5. Application will crash due to stack overflow because of line 79 in `LaunchDarkly/Extensions/Dictionary.swift` - it enters recursive loop in case of `lhs` and `rhs` both being nil.

**Expected behavior**
`==` should return true for comparison of two `nil` `[String:Any]?`objects.

**SDK version**
4.0.0

**Language version, developer tools**
Swift 5

**OS/platform**
iOS 12
torchhound commented 5 years ago

I just released iOS client 4.1.2 with your fix for this issue, thanks again for the PR!

lietusme commented 4 years ago

Created similar issue https://github.com/launchdarkly/ios-client-sdk/issues/197