fix: prevent XIM character leak in Xwayland apps under CJK locale#1594
fix: prevent XIM character leak in Xwayland apps under CJK locale#1594SHORiN-KiWATA wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesXIM forwarding behavior
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Don't forward key release events of regular printable characters while composing. Forwarding releases triggers a sync race in the XIM client's FABRICATED flag handling that can cause character leaks when COMPOUND_TEXT encoding is negotiated (which happens under CJK locales).
65affd3 to
6b49d76
Compare
|
No, not forwarding release is likely to be wrong in other case. Traditional way to fix the actual issue here is to use fcitx im module. https://fcitx-im.org/wiki/Using_Fcitx_5_on_Wayland#GTK_IM_MODULE describe how to use wayland protocol for wayland and fcitx im module for X11. |
Environment
Reproduction
LC_CTYPE=zh_CN.UTF-8(apps withLC_CTYPE=en_US.UTF-8are unaffected)XMODIFIERS=@im=fcitx; noGTK_IM_MODULEset)Root Cause
KeyPressevents but rejectKeyReleaseeventsxcb_im_forward_eventxcb_im_forward_eventsetsclient->sync = true, causing the nextKeyPressto be queuedFABRICATEDflag during forward event processing, which should be consumed by a subsequent synthetic key eventLC_CTYPE=zh_CN.UTF-8, XIM encoding negotiation selectsCOMPOUND_TEXTinstead ofUTF8_STRING, introducing encoding overhead that widens the race windowFABRICATEDflag is cleared →XFilterEventreturnsNOTFILTERD→ the client commits the character directly → leakLC_CTYPE=en_US.UTF-8negotiatesUTF8_STRINGencoding (zero overhead), making the race window too small to trigger.Fix
In the XIM frontend
XCB_XIM_FORWARD_EVENThandler, skip forwardingKeyReleaseevents of regular printable characters while the IM is composing. These releases serve no purpose for the application — it only needs commit results and preedit state, both already correctly provided by the engine. Avoiding the forward preventsclient->syncfrom being set, eliminating the root trigger of the race condition.Summary by CodeRabbit
Summary by CodeRabbit