Smithay / smithay-clipboard

Provides access to the wayland clipboard for client applications
MIT License
28 stars 11 forks source link

Fix crash when receiving non-utf8 data #13

Closed kchibisov closed 4 years ago

elinorbgr commented 4 years ago

I wonder if we should rather do some best-effort processing, reading the contents into a Vec, then converting it using String::from_utf8 and using String::from_utf8_lossy as a fallback.

chrisduerr commented 4 years ago

I wonder if we should rather do some best-effort processing, reading the contents into a Vec, then converting it using String::from_utf8 and using String::from_utf8_lossy as a fallback.

Honestly sounds like a terrible idea. To me there is no logical explanation why someone would want to paste an image as text.

kchibisov commented 4 years ago

I wonder if we should rather do some best-effort processing, reading the contents into a Vec, then converting it using String::from_utf8 and using String::from_utf8_lossy as a fallback.

Well, we're requesting utf8 string, we got non-utf8 string marked as utf8 string, so It doesn't make any sense to speculate on that and trying to make something different out of it.

elinorbgr commented 4 years ago

OK, but silently ignoring the error sounds bad to me.

In that case, maybe the clipboard access should signal the error to downstream crates (by returning a Result), so that they decide if/how they inform the user that the clipboard contained invalid data.

kchibisov commented 4 years ago

in theory clipboard should return Vec<u8> data and mime type, so the client will parse it later to something more useful, since clipboard isn't supposed to work only with utf8 text. We can return result for now though.

elinorbgr commented 4 years ago

in theory clipboard should return Vec<u8> data and mime type, so the client will parse it later to something more useful, since clipboard isn't supposed to work only with utf8 text.

This would require a more complex API though, given a single clipboard item can be provided as several different mime types, from which the receiver can choose which one is more convenient.

kchibisov commented 4 years ago

I've decided to return Result<String> for now, since we don't handle other mime types anyway.