egui icon indicating copy to clipboard operation
egui copied to clipboard

Safety hazard in Clipboard::new

Open SuchAFuriousDeath opened this issue 1 month ago • 0 comments

Describe the bug I believe that this method: https://github.com/emilk/egui/blob/8b8595b45b4c283a2a654ada081342079170e3ab/crates/egui-winit/src/clipboard.rs#L32 is not supposed to be safe.

It calls this method from smithay-clipboard (with the smithay-clipboard feature on): https://github.com/Smithay/smithay-clipboard/blob/26c2f53f15f6bdc4f41a442d0ae2c2d63bbc617c/src/lib.rs#L34, however, the safety requirements of that method cannot be guaranteed to be upheld by egui-winit.

    /// # Safety
    ///
    /// `display` must be a valid `*mut wl_display` pointer, and it must remain
    /// valid for as long as `Clipboard` object is alive.
    pub unsafe fn new(display: *mut c_void) -> Self { ... }

To Reproduce I believe that this is enough of an issue in theory, but here is a minimal demonstration of the safety hazard with 100% safe code: https://github.com/SuchAFuriousDeath/smithay-clipboard-segfault. The code in the repo segfaults when dropping the Clipboard.

Expected behavior I believe the method should be unsafe and pass the safety requirement onto the caller just like the smithay-clipboard method does.

Additional context I believe this might be the cause of #7660, but I consider this distant enough to warrant a separate issue.

SuchAFuriousDeath avatar Nov 26 '25 11:11 SuchAFuriousDeath