Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve unsafe code in GTK clipboard code #1820

Merged
merged 4 commits into from
Jun 6, 2021

Conversation

psychon
Copy link
Contributor

@psychon psychon commented Jun 6, 2021

gtk: Replace unsound std::str::from_utf8_unchecked

When putting text data into the clipboard, the platform code was calling
std::str::from_utf8_unchecked() on the data. That's not really valid,
because the caller can provide arbitrary bytes. Thus, this commit
replaces that with a call to std::str::from_utf8().

In case invalid utf8 was provided, the selection is instead set as raw
bytes. I am not sure what will happen "down the road" with this, but it
seems to be the best that can be done.

Fixes: https://github.com/linebender/druid/issues/1814
Signed-off-by: Uli Schlachter <psychon@znc.in>

I also reported gtk-rs/gtk3-rs#564 to make gdk::Atom::value() safe (or at least to figure out why it is unsafe).

Signed-off-by: Uli Schlachter <psychon@znc.in>
When putting text data into the clipboard, the platform code was calling
std::str::from_utf8_unchecked() on the data. That's not really valid,
because the caller can provide arbitrary bytes. Thus, this commit
replaces that with a call to std::str::from_utf8().

In case invalid utf8 was provided, the selection is instead set as raw
bytes. I am not sure what will happen "down the road" with this, but it
seems to be the best that can be done.

Fixes: linebender#1814
Signed-off-by: Uli Schlachter <psychon@znc.in>
Signed-off-by: Uli Schlachter <psychon@znc.in>
Signed-off-by: Uli Schlachter <psychon@znc.in>
@jneem jneem merged commit 0a68672 into linebender:master Jun 6, 2021
@psychon psychon deleted the gtk-clipboard-unsafe-str branch June 9, 2021 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants