You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Editor: IME and dictation can crash the app through unguarded ranges in TextView+NSTextInput #2339
Found while fixing #2338 (an empty NSBezierPath reaching bounds inside drawRect). Same crash class: an AppKit call raises an ObjC exception, and on macOS 26 and later that terminates the app.
// line 241
letrealRange=(textStorage.stringasNSString).rangeOfComposedCharacterSequences(for:range)
// line 243
return textStorage.attributedSubstring(from:realRange)
The doc comment directly above says the implementation "should be prepared for aRange to be out of bounds", should return the intersection, and should return nil when the location is completely outside. Neither call does that. Both raise: rangeOfComposedCharacterSequences(for:) with NSInvalidArgumentException ("The index N is invalid", the same reason string as the crash fixed in #1835), attributedSubstring(from:) with NSRangeException. Both measured on macOS 27 with an Obj-C @try/@catch probe.
firstRect(forCharacterRange:actualRange:) at line 263 has the same shape, and the input context polls it while a candidate window is open.
The callers are outside our control: any IME (CJK candidate windows), dictation, the character viewer and Ink all call these with ranges they computed earlier. A stale range is normal traffic here, not an edge case.
Fix: clamp to the storage length and return nil when the range does not intersect it, which is what the doc comment already specifies.
Activity