From c9f1f0e12c8b87bcfacb850257c3531ddd3506dc Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 13 Feb 2022 07:34:47 -0700 Subject: [PATCH] window: x11: avoid potential crash when pasting non-utf8 text This might "break" eg: pasting from apps that just use ATOM_STRING and that happen to have utf-8 compatible text. Ideally the get_text_property interface would expose the actual text encoding in the returned data and allow the application to "do stuff" with it. refs: https://github.com/meh/rust-xcb-util/issues/21 --- window/src/os/x11/window.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/window/src/os/x11/window.rs b/window/src/os/x11/window.rs index 731e43040..09d3e9895 100644 --- a/window/src/os/x11/window.rs +++ b/window/src/os/x11/window.rs @@ -574,16 +574,21 @@ impl XWindowInner { let conn = self.conn(); log::trace!( - "SELECTION_NOTIFY received selection={} (prim={} clip={}) target={} property={}", + "SELECTION_NOTIFY received selection={} (prim={} clip={}) target={} property={} utf8={}", selection.selection(), xcb::ATOM_PRIMARY, conn.atom_clipboard, selection.target(), - selection.property() + selection.property(), + self.conn().atom_utf8_string, ); if let Some(clipboard) = self.selection_atom_to_clipboard(selection.selection()) { - if selection.property() != xcb::NONE { + if selection.property() != xcb::NONE + // Restrict to strictly UTF-8 to avoid crashing; see + // + && selection.target() == self.conn().atom_utf8_string + { match xcb_util::icccm::get_text_property( &conn, selection.requestor(),