New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SR-391] _CFSwiftDictionaryGetKeysAndValues() crashes with NULL arguments #4192
Comments
Bridging a dictionary that contains NULL values is an error and cannot be properly represented by NSDictionary. The nullability markers on NSDictionary, NSArray, and NSSet are technically incorrect and should eventually be updated for the arrays of elements that can be null by declaration; since NSDictionary, NSArray and NSSet are not expected to be able to store nil. |
It's not about NULL values, it's about the top-level keybuf/valbuf pointer to _CFSwiftDictionaryGetKeysAndValues(). |
ah ok, yes that is correct; but the signature of UnsafeMutablePointer<Unmanaged<AnyObject>?> does not need to change for that since UnsafeMutablePointer can be compared to nil via NilLiteralConvertible, this should be a relatively easy fix |
Right, this works for me: internal func _CFSwiftDictionaryGetKeysAndValues(dictionary: AnyObject, keybuf: UnsafeMutablePointer<Unmanaged<AnyObject>?>, valuebuf: UnsafeMutablePointer<Unmanaged<AnyObject>?>) {
var idx = 0
(dictionary as! NSDictionary).enumerateKeysAndObjectsUsingBlock { key, value, _ in
if keybuf != nil {
keybuf[idx] = Unmanaged<AnyObject>.passUnretained(key)
}
if valuebuf != nil {
valuebuf[idx] = Unmanaged<AnyObject>.passUnretained(value)
}
idx += 1
}
} |
integrated in 0b43114 |
Additional Detail from JIRA
md5: 9406824d62d27e835af51e42e1d7de5c
blocks:
Issue Description:
It's valid to enumerate a dictionary with CFDictionaryGetKeysAndValues(), only retrieving the keys or values (or indeed nothing). See:
https://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFDictionaryRef/#//apple_ref/c/func/CFDictionaryGetKeysAndValues
Thus, _CFSwiftDictionaryGetKeysAndValues needs to check keybuf and valuebuf are non-nil before assigning to them.
The text was updated successfully, but these errors were encountered: