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
Commit 4e7ae1e
Browse filesBrowse the repository at this point in the historyBrowse files
macOS: Fix crash on out-of-bounds text input ranges
`TextInputModel` assumes its selection and composing range fall within
its text, but nothing in the text input plugin enforced that. When they
don't, we index past the end of `text_` which triggers an abort due to
out of range access.
```
out_of_range was thrown in -fno-exceptions mode with message "basic_string"
```
Previously, `setMarkedText:selectedRange:replacementRange:` passed
`selectedRange` unvalidated. IMEs report `NSNotFound` to indicate no
selection within the mark text. That maps to `NSIntegerMax` rather than
an offset, and we incorrectly stored that as the selection. Clearing the
marked text collapses the composing range, so the next update replaces
the selection instead and calls `replace` with a position
`NSIntegerMax`. Clear and re-mark is what an input method emits when the
input source is switched mid-composition.
`SetText` was also unsafe: it assigned `text_` before validating the
ranges, so a rejected update left us with the new text but the old (now
out-of-bounds) ranges still pointing into it.
This fixes that by clamping both ranges before any operation that
indexes the text, applying either all of `SetText`'s fields or none, and
clamping `selectedRange` and `replacementRange` in the plugin.
`setMarkedText:` also null-checks the UTF-16 buffer, which
`cStringUsingEncoding:` can return as nullptr.
Fixes: flutter#190704
0 commit comments