Repository navigation
[Linux] App aborts with wstring_convert: to_bytes error when typing with an IME — TextInputModel::DeleteSurrounding splits UTF-16 surrogate pairs #190046
Copy link
Copy link
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemsc: crashStack traces logged to the consoleStack traces logged to the consolec: fatal crashCrashes that terminate the processCrashes that terminate the processengineflutter/engine related. See also e: labels.flutter/engine related. See also e: labels.platform-linuxBuilding on or for Linux specificallyBuilding on or for Linux specificallyteam-linuxOwned by the Linux platform teamOwned by the Linux platform teamtriaged-linuxTriaged by the Linux platform teamTriaged by the Linux platform team
Description
Activity
- addedin triagePresently being triaged by the triage teamPresently being triaged by the triage teama: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemsc: crashStack traces logged to the consoleStack traces logged to the consoleengineflutter/engine related. See also e: labels.flutter/engine related. See also e: labels.platform-linuxBuilding on or for Linux specificallyBuilding on or for Linux specificallyc: fatal crashCrashes that terminate the processCrashes that terminate the processteam-linuxOwned by the Linux platform teamOwned by the Linux platform teamfyi-engineFor the attention of Engine teamFor the attention of Engine teamand removedin triagePresently being triaged by the triage teamPresently being triaged by the triage team
on Jul 28, 2026 HI @chen00054, thanks for the detailed report and for pointing to the source code.
Routing to the Linux team for evaluation.@mbcorona I think it's generally better to let downstream engineers use the
fyi-enginelabel as a way for engineers to tag in other teams if they need help.Reacted by Bruno Corona- removedfyi-engineFor the attention of Engine teamFor the attention of Engine team
on Aug 3, 2026 Opened PR #190514 resolve this issue
- added 2 commits that reference this issue
on Aug 5, 2026 - added a commit that references this issue
on Aug 18, 2026 - addedP2Important issues not at the top of the work listImportant issues not at the top of the work listtriaged-linuxTriaged by the Linux platform teamTriaged by the Linux platform team
on Aug 19, 2026 While filed against Linux, the fix suggests this could affect multiple platforms.
- added a commit that references this issue
on Sep 3, 2026 This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.- locked as resolved and limited conversation to collaborators
on Sep 17, 2026
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemsc: crashStack traces logged to the consoleStack traces logged to the consolec: fatal crashCrashes that terminate the processCrashes that terminate the processengineflutter/engine related. See also e: labels.flutter/engine related. See also e: labels.platform-linuxBuilding on or for Linux specificallyBuilding on or for Linux specificallyteam-linuxOwned by the Linux platform teamOwned by the Linux platform teamtriaged-linuxTriaged by the Linux platform teamTriaged by the Linux platform team
Steps to reproduce
Environment: Debian 12 desktop, ibus with a Chinese Wubi (五笔) input method (e.g.
ibus-table-wubi) — any IME engine that uses GTK surrounding-text /delete-surroundingshould work.TextField(release or debug — the crash is in the engine).a😀.delete-surroundingrequest covering the BMP character and the emoji (Chinese IMEs do this routinely for reconversion / candidate replacement).The crash is probabilistic at the UI level (it depends on the IME issuing
delete-surroundingacross an emoji), but it is deterministic at the unit level — see the minimal reproduction below, which needs no IME at all.Minimal reproduction (engine unit test)
Trace of
DeleteSurrounding(0, 2)withtext_ = {'a', 0xD83D, 0xDE00},start = 0:end += IsLeadingSurrogate(text_.at(start /* =0, 'a' */)) ? 2 : 1→end = 1end += IsLeadingSurrogate(text_.at(start /* still 0, 'a' */)) ? 2 : 1→end = 2(should have checked
text_.at(end /* =1, 0xD83D */)and advanced by 2)text_.erase(0, 2)removes'a'and the lead surrogate only, leaving a lone trail surrogate0xDE00intext_.The next
GetText()(called unconditionally at the top ofim_delete_surrounding_cb, and byupdate_editing_state) runsfml::Utf16ToUtf8→std::wstring_convert::to_bytes, which throwsstd::range_erroron the lone surrogate. The engine is built with-fno-exceptions, so this is an immediate abort:Root cause
TextInputModel::DeleteSurroundingadvancesendby checking the character atstartinstead of atend:flutter/engine/src/flutter/shell/platform/common/text_input_model.cc
Lines 207 to 210 in 058e0af
Consequences:
endlands mid-surrogate-pair,eraseleaves a lone surrogate intext_, and the next UTF-16→UTF-8 conversion aborts the process;endover-advances and deletes more text than requested (silent data corruption).Crash entry point on Linux (GTK
delete-surrounding, used heavily by Chinese/Japanese IMEs over ibus/fcitx):flutter/engine/src/flutter/shell/platform/linux/fl_text_input_handler.cc
Lines 226 to 241 in 058e0af
Note that
DeleteSurroundingis inshell/platform/common, so Windows is affected by the same defect as well (Windows reaches it through its own text input plugin paths).Related hardening opportunity
TextInputModel::GetCursorOffsetis a second unguarded conversion site: ifselection_.extent()ever lands inside a surrogate pair (e.g. via an inconsistent preedit cursor offset fromim_preedit_changed_cb),substrproduces a string ending in a lone lead surrogate andfml::Utf16ToUtf8aborts the same way:flutter/engine/src/flutter/shell/platform/common/text_input_model.cc
Lines 301 to 306 in 058e0af
Since
fml::Utf16ToUtf8/Utf8ToUtf16(std::wstring_convert, deprecated since C++17) turn any invalid input into a process abort under-fno-exceptions, it may be worth making the conversion lenient (replacement character) in addition to fixing the call sites. This is the same failure signature as #154072 and the macOS issue #182443.Expected results
Deleting surrounding text that contains non-BMP characters deletes whole code points; the app does not crash.
Actual results
The app aborts with:
Suggested fix
Flutter version
Reproduced on Debian 12 (GNOME/X11, ibus). The defect is present on current
master—text_input_model.cchas not been modified since the code was introduced.