Skip to content

Instantly share code, notes, and snippets.

@xsscx
Created August 26, 2024 13:25
Show Gist options
  • Save xsscx/7bb6ca9afa1966eba51beb0013cfe505 to your computer and use it in GitHub Desktop.
Save xsscx/7bb6ca9afa1966eba51beb0013cfe505 to your computer and use it in GitHub Desktop.
Test to reproduce crash in the Preferences app when entering a specific string in the search field.
import XCTest
class CSSearchQuery_UITests: XCTestCase {
// MARK: - Test Methods
/// Test to reproduce crash in the Preferences app when entering a specific string in the search field.
func testPreferencesSearchCrash() throws {
// Initialize the Preferences app
let app = XCUIApplication(bundleIdentifier: "com.apple.Preferences")
app.launch()
// Wait for the initial screen to load
XCTAssertTrue(app.waitForExistence(timeout: 10), "Failed to launch the Preferences app within the expected time.")
// Swipe down to expose the search field
let firstElement = app.otherElements.firstMatch
firstElement.swipeDown()
// Locate the search field after the swipe gesture
let searchField = app.searchFields.firstMatch
let exists = searchField.waitForExistence(timeout: 10)
// MARK: - Debugging
// If the search field exists, attempt to type the crash-inducing input
if exists {
searchField.tap()
searchField.typeText("\"\":a") // Adjust this pattern as needed to trigger the crash
} else {
XCTFail("Search field not found or not accessible.")
// Debugging: Output the entire UI hierarchy for inspection
print(app.debugDescription)
}
}
// MARK: - Helper Methods
/// Helper method to log additional information when debugging.
private func logDebugInfo(for app: XCUIApplication) {
// Print the UI hierarchy to help identify issues with element visibility or accessibility
print(app.debugDescription)
// Additional debugging information can be logged here if needed
}
}
@xsscx
Copy link
Author

xsscx commented Aug 26, 2024

Crash

Coalition:           com.apple.CoreSimulator.SimDevice.E9FD4EA5-B94E-4E31-8337-7725D6997B51 [2983]
Responsible Process: SimulatorTrampoline [660]

Date/Time:           2024-08-26 09:19:37.6778 -0400
Launch Time:         2024-08-26 09:19:23.0064 -0400
OS Version:          macOS 14.6.1 (23G93)
Release Type:        User
Report Version:      104

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000000
Exception Codes: 0x0000000000000001, 0x0000000000000000
VM Region Info: 0 is not in any region.  Bytes before following region: 4517892096
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  
      __TEXT                      10d499000-10d5d6000    [ 1268K] r-x/r-x SM=COW  /Volumes/VOLUME/*/Preferences.app/Preferences
Termination Reason: SIGNAL 11 Segmentation fault: 11
Terminating Process: exc handler [95225]

Triggered by Thread:  0

Kernel Triage:
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter


Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   ???                           	               0x0 ???
1   MetadataUtilities             	    0x7ff81b9a159b renderQueryPredicate + 143
2   MetadataUtilities             	    0x7ff81b9a1349 renderParseTreeToQuery + 1336
3   MetadataUtilities             	    0x7ff81b9a46ea __MDQueryCreateQueryDictionaryWithOptionsDict + 3345
4   CoreSpotlight                 	    0x7ff8172ed4e2 -[CSUserQueryParser _CSQueryCreateQueryDictionaryWithOptionsDict:attribute:input:options:] + 29
5   CoreSpotlight                 	    0x7ff8173027da -[CSSearchQuery initWithQueryString:context:] + 253
6   CoreSpotlight                 	    0x7ff81728c648 -[CSUserQuery initWithQueryString:context:] + 67
7   CoreSpotlight                 	    0x7ff8172f1952 -[CSTopHitSearchQuery initWithQueryString:context:] + 391
8   CoreSpotlight                 	    0x7ff8172f1d0b -[CSTopHitSearchQuery initWithSearchString:keyboardLanguage:attributes:hitCount:] + 216
9   Preferences                   	    0x7ff810c97eb6 -[PSCoreSpotlightIndexer topHitSearchForString:keyboardLanguage:foundItemsHandler:completionHandler:] + 286
10  PreferencesUI                 	    0x7ff91d8022bb -[PSUIPrefsListController updateSearchResultsForSearchController:] + 589
11  UIKitCore                     	    0x7ff805d4def2 -[UISearchController _ios_searchBar:textDidChange:programatically:] + 229
12  UIKitCore                     	    0x7ff804f47cbc -[UISearchBar _searchFieldTextChanged:] + 325
13  UIKitCore                     	    0x7ff805cc6c07 -[UIApplication sendAction:to:from:forEvent:] + 95
14  UIKitCore                     	    0x7ff80533b1ab -[UIControl sendAction:to:forEvent:] + 112
15  UIKitCore                     	    0x7ff80533b5a0 -[UIControl _sendActionsForEvents:withEvent:] + 334
16  UIKitCore                     	    0x7ff80610d730 -[UITextField fieldEditorDidChange:] + 202
17  UIKitCore                     	    0x7ff804f5561c -[UISearchTextField fieldEditorDidChange:] + 67
18  UIKitCore                     	    0x7ff8060f0b1e -[UIFieldEditor textInputDidChange:] + 65
19  UIKitCore                     	    0x7ff806120a74 -[UITextInputController _sendDelegateChangeNotificationsForText:selection:] + 182
20  UIKit                         	    0x7ffa0e125113 -[UITextInputControllerAccessibility _sendDelegateChangeNotificationsForText:selection:] + 83
21  UIKitCore                     	    0x7ff806122d7d -[UITextInputController _insertText:fromKeyboard:] + 1032
22  UIKitCore                     	    0x7ff806124099 -[UITextInputController insertText:] + 710
23  UIKitCore                     	    0x7ff8060f3c2a -[UIFieldEditor _handleObscuredTextInputIfNecessaryWithEditingBlock:] + 565
24  UIKitCore                     	    0x7ff8060f3ef6 -[UIFieldEditor insertFilteredText:] + 506
25  UIKitCore                     	    0x7ff8061138cf -[UITextField insertFilteredText:] + 93
26  UIKitCore                     	    0x7ff804f5359a -[UISearchTextField insertFilteredText:] + 198
27  UIKitCore                     	    0x7ff805569928 -[UIKBInputDelegateManager insertText:updateInputSource:] + 473
28  UIKit                         	    0x7ffa0e007ae6 -[UIKBInputDelegateManagerAccessibility insertText:updateInputSource:] + 102
29  UIKitCore                     	    0x7ff80556246f -[UIKBInputDelegateManager insertText:] + 115
30  UIKitCore                     	    0x7ff805a0b61f -[UIKeyboardImpl performKeyboardOutput:checkingDelegate:forwardToRemoteInputSource:] + 6324
31  UIKit                         	    0x7ffa0e083bb6 -[UIKeyboardImplAccessibility performKeyboardOutput:checkingDelegate:forwardToRemoteInputSource:] + 134
32  UIKitCore                     	    0x7ff805a09a12 -[UIKeyboardImpl performKeyboardOutput:forwardToRemoteInputSource:] + 32
33  UIKitCore                     	    0x7ff805a099dc -[UIKeyboardImpl performKeyboardOutput:] + 135
34  UIKitCore                     	    0x7ff805a1ae86 -[UIKeyboardImpl addInputString:withFlags:withInputManagerHint:withInputSource:executionContext:] + 1247
35  UIKitCore                     	    0x7ff805a1a9a1 -[UIKeyboardImpl addInputString:withFlags:withInputManagerHint:executionContext:] + 28
36  UIKitCore                     	    0x7ff805a186e9 -[UIKeyboardImpl handleStringInput:withFlags:withInputManagerHint:executionContext:] + 271
37  UIKitCore                     	    0x7ff805a41daa -[UIKeyboardImpl handleKeyWithString:forKeyEvent:executionContext:] + 989
38  UIKitCore                     	    0x7ff8059da17e -[UIKeyboardImpl performOperations:withTextInputSource:] + 34
39  UIKitCore                     	    0x7ff805a4149d -[UIKeyboardImpl handleKeyEvent:executionContext:] + 4316
40  UIKitCore                     	    0x7ff805a3ffbe __33-[UIKeyboardImpl handleKeyEvent:]_block_invoke + 45
41  UIKitCore                     	    0x7ff805a6ab2c -[UIKeyboardTaskEntry execute:] + 193
42  UIKitCore                     	    0x7ff805a692b6 -[UIKeyboardTaskQueue continueExecutionOnMainThread] + 376
43  Foundation                    	    0x7ff800eb4960 __NSThreadPerformPerform + 178
44  CoreFoundation                	    0x7ff800429fb3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
45  CoreFoundation                	    0x7ff800429ef5 __CFRunLoopDoSource0 + 157
46  CoreFoundation                	    0x7ff8004296f2 __CFRunLoopDoSources0 + 215
47  CoreFoundation                	    0x7ff800423e27 __CFRunLoopRun + 919
48  CoreFoundation                	    0x7ff8004236ad CFRunLoopRunSpecific + 557
49  GraphicsServices              	    0x7ff8103da08f GSEventRunModal + 137
50  UIKitCore                     	    0x7ff805cc0ad1 -[UIApplication _run] + 972
51  UIKitCore                     	    0x7ff805cc5551 UIApplicationMain + 123
52  Preferences                   	       0x10d4e7661 0x10d499000 + 321121
53  Preferences                   	       0x10d4e73f9 0x10d499000 + 320505
54  dyld_sim                      	       0x10d6283e0 start_sim + 10
55  dyld                          	       0x1157e5345 start + 1909

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment