brave / brave-browser

Brave browser for Android, iOS, Linux, macOS, Windows.
https://brave.com
Mozilla Public License 2.0
17.8k stars 2.33k forks source link

Launching the app via the Shortcuts Widget Search button may crash #41457

Closed kylehickinson closed 3 weeks ago

kylehickinson commented 3 weeks ago

Description

There's a possible race condition that can happen when launching the app with the shortcuts widget, specifically the "Search" button which highlights the URL bar immediately.

Steps to reproduce

  1. Add a Shorcuts widget to the home screen and ensure the app is fully closed (force kill from app switcher)
  2. Tap the "Search or type URL" shortcut link in the widget

Actual result

In some situations, the app will crash

Expected result

No crash

Reproduces how often

Intermittent issue

Brave version

1.69+

Device/iOS version

any

Affected browser versions

Reproducibility

Miscellaneous information

Crash Log ``` Incident Identifier: 23CF8FE5-5852-46B4-8E7F-1B9843D6AB63 Distributor ID: com.apple.AppStore Hardware Model: iPhone16,1 Process: Client [2692] Path: /private/var/containers/Bundle/Application/4C8C0559-9EA5-4085-B438-CB20AF0D1E9D/Client.app/Client Identifier: com.brave.ios.browser Version: 1.69.2 (172) AppStoreTools: 16A242b AppVariant: 1:iPhone16,1:18 Code Type: ARM-64 (Native) Role: Foreground Parent Process: launchd [1] Coalition: com.brave.ios.browser [1699] Date/Time: 2024-10-07 12:17:57.9627 +0200 Launch Time: 2024-10-07 10:14:53.2044 +0200 OS Version: iPhone OS 18.1 (22B5054e) Release Type: Beta Baseband Version: 2.20.02 Report Version: 104 Exception Type: EXC_BREAKPOINT (SIGTRAP) Exception Codes: 0x0000000000000001, 0x00000001026176a4 Termination Reason: SIGNAL 5 Trace/BPT trap: 5 Terminating Process: exc handler [2692] Triggered by Thread: 0 Thread 0 Crashed: 0 Client 0x00000001026176a4 Swift runtime failure: Index out of range + 0 (:0) 1 Client 0x00000001026176a4 specialized Array._checkSubscript(_:wasNativeTypeChecked:) + 0 (:0) 2 Client 0x00000001026176a4 specialized Array.subscript.getter + 0 (:0) 3 Client 0x00000001026176a4 SearchEngines.defaultEngine(forType:) + 492 4 Client 0x000000010242b298 SearchEngines.queryForSearchURL(_:forType:) + 8 (SearchEngines.swift:254) 5 Client 0x000000010242b298 BrowserViewController.topToolbarDisplayTextForURL(_:) + 1036 (BVC+ToolbarDelegate.swift:199) 6 Client 0x00000001026da4ec protocol witness for TopToolbarDelegate.topToolbarDisplayTextForURL(_:) in conformance BrowserViewController + 12 (:0) 7 Client 0x00000001026da4ec specialized TopToolbarView.tabLocationViewDidTapLocation(_:) + 308 (TopToolbarView.swift:848) 8 Client 0x00000001024ed0fc TopToolbarView.tabLocationViewDidTapLocation(_:) + 8 (BrowserViewController.swift:3229) 9 Client 0x00000001024ed0fc BrowserViewController.focusURLBar() + 8 (:0) 10 Client 0x00000001024ed0fc specialized static NavigationPath.handleWidgetShortcut(_:with:) + 2784 11 Client 0x00000001024ed4ac static NavigationPath.handleWidgetShortcut(_:with:) + 8 (:0) 12 Client 0x00000001024ed4ac specialized static NavigationPath.handle(nav:with:) + 556 (NavigationRouter.swift:82) 13 Client 0x00000001024a6b30 thunk for @escaping @callee_guaranteed () -> () + 4 (:0) 14 Client 0x00000001024a6b30 partial apply for thunk for @escaping @callee_guaranteed () -> () + 20 15 Client 0x00000001024a7d8c thunk for @escaping @callee_guaranteed () -> (@out ()) + 4 (:0) 16 Client 0x00000001024a7d8c partial apply for thunk for @escaping @callee_guaranteed () -> (@out ()) + 20 17 Client 0x00000001024a7dac closure #1 in BrowserViewController.setupTabs() + 4 (BrowserViewController.swift:1187) 18 Client 0x00000001024a7dac partial apply for closure #1 in BrowserViewController.setupTabs() + 20 (:0) 19 Client 0x00000001023b3888 thunk for @escaping @callee_guaranteed () -> () + 28 (:0) 20 libdispatch.dylib 0x00000001a3463370 _dispatch_call_block_and_release + 32 (init.c:1549) 21 libdispatch.dylib 0x00000001a34650d0 _dispatch_client_callout + 20 (object.m:576) 22 libdispatch.dylib 0x00000001a34739e0 _dispatch_main_queue_drain + 980 (queue.c:8093) 23 libdispatch.dylib 0x00000001a34735fc _dispatch_main_queue_callback_4CF + 44 (queue.c:8253) 24 CoreFoundation 0x000000019b771204 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16 (CFRunLoop.c:1793) 25 CoreFoundation 0x000000019b76e440 __CFRunLoopRun + 1996 (CFRunLoop.c:3163) 26 CoreFoundation 0x000000019b76d830 CFRunLoopRunSpecific + 588 (CFRunLoop.c:3434) 27 GraphicsServices 0x00000001e7a851c4 GSEventRunModal + 164 (GSEvent.c:2196) 28 UIKitCore 0x000000019e2db9a4 -[UIApplication _run] + 816 (UIApplication.m:3835) 29 UIKitCore 0x000000019e38a168 UIApplicationMain + 340 (UIApplication.m:5487) 30 UIKitCore 0x000000019e6c2478 UIApplicationMain(_:_:_:_:) + 104 (UIKit.swift:565) 31 Client 0x000000010238659c specialized static UIApplicationDelegate.main() + 28 (:38) 32 Client 0x000000010238659c static AppDelegate.$main() + 28 (AppDelegate.swift:0) 33 Client 0x000000010238659c main + 120 34 dyld 0x00000001c149dec8 0x1c146a000 + 212680 ```
kjozwiak commented 3 weeks ago

The above requires 1.70.126 or higher for 1.70.x verification 👍

hffvld commented 3 weeks ago

Verified on iPhone 14 using version(s):

Device/OS: iPhone 14 / iOS 17.7
Brave build: 1.70 (126)
BraveCore: 1.70.126 (129.0.6668.100)

STEPS:

  1. Follow the STR/TP from https://github.com/brave/brave-browser/issues/41457#issue-2571527554 and https://github.com/brave/brave-core/pull/25862#issuecomment-2400760940
  2. Verify

ACTUAL RESULTS:


https://github.com/user-attachments/assets/0bbb8126-0bd6-4120-a64b-30c69a5df1e3