Declaring Existing Name in UIViewController extension in Framework Causes Crash
| Originator: | daniel | ||
| Number: | rdar://34271274 | Date Originated: | 05-Sep-2017 06:45 PM |
| Status: | Open | Resolved: | |
| Product: | iOS + SDK | Product Version: | Version 9.0 beta 6 (9M214v) |
| Classification: | Security | Reproducible: | Always |
Summary:
If, in a dynamic framework, an extension to UIViewController declares a computed property such as `navigationBar`, whose name may collide with a subclass of UIViewController (UINavigationController, in this case), this will cause a crash.
Steps to Reproduce:
1. make a framework (“CrashKit”), in it, add the following code.
import UIKit
extension UIViewController {
public var navigationBar: UINavigationBar? {
return nil
}
}
2. In the same Xcode project, import the framework from step 1 and make a subclass to UINavigationController, present an instance of it. For example:
import CrashKit
import UIKit
open class XX: UINavigationController {
open override func viewDidLoad() {
super.viewDidLoad()
print(">>>", self.navigationBar)
}
}
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
self.window = UIWindow(frame: UIScreen.main.bounds)
let rootVC = XX()
self.window?.rootViewController = rootVC
self.window?.makeKeyAndVisible()
return true
}
}
3. run the project, observe that a crash happens with stack trace similar to this:
2017-09-05 18:34:17.991455-0700 Crash[81376:11788976] -[Crash.XX decodeObjectForKey:]: unrecognized selector sent to instance 0x7f8922823400
2017-09-05 18:34:18.000151-0700 Crash[81376:11788976] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Crash.XX decodeObjectForKey:]: unrecognized selector sent to instance 0x7f8922823400'
*** First throw call stack:
(
0 CoreFoundation 0x00000001122cf1cb __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010e9a9f41 objc_exception_throw + 48
2 CoreFoundation 0x000000011234f914 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 UIKit 0x000000010f1967a5 -[UIResponder doesNotRecognizeSelector:] + 295
4 CoreFoundation 0x0000000112252178 ___forwarding___ + 1432
5 CoreFoundation 0x0000000112251b58 _CF_forwarding_prep_0 + 120
6 UIKit 0x000000010f10eb89 -[UIViewController initWithCoder:] + 311
7 Crash 0x000000010e0912f2 _T05Crash14ViewControllerCACSgSo7NSCoderC5coder_tcfc + 66
8 Crash 0x000000010e091544 _T05Crash2XXC11viewDidLoadyyF + 212
9 Crash 0x000000010e091664 _T05Crash2XXC11viewDidLoadyyFTo + 36
10 UIKit 0x000000010f113fe7 -[UIViewController loadViewIfRequired] + 1235
11 UIKit 0x000000010f114434 -[UIViewController view] + 27
12 UIKit 0x000000010efeaa8b -[UIWindow addRootViewControllerViewIfPossible] + 122
13 UIKit 0x000000010efeb17d -[UIWindow _setHidden:forced:] + 294
14 UIKit 0x000000010effe01f -[UIWindow makeKeyAndVisible] + 42
15 Crash 0x000000010e09228d _T05Crash11AppDelegateC11applicationSbSo13UIApplicationC_s10DictionaryVySC0E16LaunchOptionsKeyVypGSg022didFinishLaunchingWithH0tF + 589
16 Crash 0x000000010e09250a _T05Crash11AppDelegateC11applicationSbSo13UIApplicationC_s10DictionaryVySC0E16LaunchOptionsKeyVypGSg022didFinishLaunchingWithH0tFTo + 186
17 UIKit 0x000000010ef70dfa -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 267
18 UIKit 0x000000010ef72857 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4105
19 UIKit 0x000000010ef77ce5 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1720
20 UIKit 0x000000010f325118 __111-[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:]_block_invoke + 924
21 UIKit 0x000000010f6e8e57 +[_UICanvas _enqueuePostSettingUpdateTransactionBlock:] + 153
22 UIKit 0x000000010f324d11 -[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:] + 249
23 UIKit 0x000000010f32556f -[__UICanvasLifecycleMonitor_Compatability activateEventsOnly:withContext:completion:] + 668
24 UIKit 0x000000010fc625b9 __82-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:]_block_invoke + 262
25 UIKit 0x000000010fc62472 -[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] + 444
26 UIKit 0x000000010f95f646 __125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke + 420
27 UIKit 0x000000010fb54e0e _performActionsWithDelayForTransitionContext + 100
28 UIKit 0x000000010f95f442 -[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] + 231
29 UIKit 0x000000010f6e84b4 -[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] + 392
30 UIKit 0x000000010ef76566 -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 523
31 UIKit 0x000000010f529c8b -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 369
32 FrontBoardServices 0x0000000118b9f374 -[FBSSceneImpl _didCreateWithTransitionContext:completion:] + 338
33 FrontBoardServices 0x0000000118ba7e69 __56-[FBSWorkspace client:handleCreateScene:withCompletion:]_block_invoke_2 + 235
34 libdispatch.dylib 0x000000011337643c _dispatch_client_callout + 8
35 libdispatch.dylib 0x000000011337baf4 _dispatch_block_invoke_direct + 592
36 FrontBoardServices 0x0000000118bd376e __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
37 FrontBoardServices 0x0000000118bd3424 -[FBSSerialQueue _performNext] + 464
38 FrontBoardServices 0x0000000118bd3993 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
39 CoreFoundation 0x00000001122722b1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
40 CoreFoundation 0x0000000112311d31 __CFRunLoopDoSource0 + 81
41 CoreFoundation 0x0000000112256c19 __CFRunLoopDoSources0 + 185
42 CoreFoundation 0x00000001122561ff __CFRunLoopRun + 1279
43 CoreFoundation 0x0000000112255a89 CFRunLoopRunSpecific + 409
44 GraphicsServices 0x00000001171179c6 GSEventRunModal + 62
45 UIKit 0x000000010ef797d0 UIApplicationMain + 159
46 Crash 0x000000010e092bd7 main + 55
47 libdyld.dylib 0x00000001133f2d81 start + 1
48 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Expected Results:
There shouldn’t be a crash.
Actual Results:
There’s a crash when `navigationBar` is accessed from an `UINavigationController` subclass.
Version:
Version 9.0 beta 6 (9M214v)
Notes:
I’ve attached an sample Xcode project that demonstrates it. Just open and run and you’ll see this problem in action.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!