#Crash macOS app typing query, triggered by "[NSString _newSubstringWithRange:zone:]"

1 messages · Page 1 of 1 (latest)

low herald
#

Steps to reproduce:
Crash exception was triggered by "-[NSString _newSubstringWithRange:zone:]" in macOS app: Related to an invalid range or a manipulation of an NSString object. Likely reasons:

  • An attempt to access a substring with an invalid range.
  • Corruption or invalid state in the text storage or undo manager.
  • An unexpected nil value or invalid object being used during text editing.

Medium conversation, maybe 15 or so queries, cut text in the query, pressed the "new" conversation button. Began to type text query in blank conversation, app simply crashed

Expected result:
Continuing to type a query, macOS app should not crash

Actual result:
Crash in Version 1.2024.157 (1718053765) macOS ChatGPT app
At "_newSubstringWithRange" call.
See VIDEO and CRASH LOG, which indicates:

Uncaught exception thrown, specifically involves NSTextView and NSTextStorage classes in AppKit framework, which are responsible for managing text and its attributes in macOS applications

QA below will help in reducing likelihood of similar future crashes.

Insights:

  1. Validate Text Ranges: Ensure that all text manipulations and range accesses are validated. Avoid accessing substrings with invalid ranges.

  2. Exception Handling: Implement robust exception handling around text manipulation code to catch and handle exceptions gracefully.

  3. Debugging and Logging: Add detailed logging around text input and editing operations to capture more context when exceptions occur. This can help identify the exact conditions leading to the crash.

  4. Review Undo Management: Examine the use of NSUndoManager and related undo/redo operations to ensure they are correctly managed and do not lead to inconsistent states.

  5. Test Edge Cases: Perform thorough testing of text input fields, including edge cases such as very large text, rapid typing, and undo/redo operations.

Additional information
Browser: not in browser, in macOS app version: 1.2024.157 (1718053765)
OS: macOS 14.5 (23F79)