Guard surrounding_text against out-of-bounds cursor/anchor offsets#133
Open
thereisnotime wants to merge 1 commit into
Open
Guard surrounding_text against out-of-bounds cursor/anchor offsets#133thereisnotime wants to merge 1 commit into
thereisnotime wants to merge 1 commit into
Conversation
The compositor's cursor and anchor byte offsets are passed straight into QString::fromUtf8 as lengths with no validation. A bogus offset larger than the text (KWin on Plasma 6 sends values like 6881396) makes fromUtf8 read past the end of the buffer and segfault, which is the frequent maliit-keyboard crash in maliit/keyboard#262. Clamp cursor and anchor to the text length before use.
363314c to
4f527b0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Wayland input-method
surrounding_texthandler inconnection/waylandinputmethodconnection.cppuses the compositor-suppliedcursorandanchorbyte offsets directly asQString::fromUtf8lengths, with no bounds check:When a compositor sends an offset larger than the text (KWin on Plasma 6 sends values like 6881396),
fromUtf8reads past the end of the buffer and the process segfaults in_mm_loadu_si128. This is the frequent maliit-keyboard crash reported in maliit/keyboard#262 (and earlier in #86), and it makes the keyboard drop out constantly on Fedora 43 + Plasma 6 Wayland.This clamps
cursorandanchorto the actual UTF-8 length before they are used as offsets/lengths, which also keeps thebegin/endselection slice in bounds. It is purely defensive: valid offsets are unchanged.Refs maliit/keyboard#262.