On Mon, 8 Dec 2025 15:11:08 GMT, Lukasz Kostyra <[email protected]> wrote:

>> This commit fixes the JVM crash caused by bad Clipboard data on Linux.
>> 
>> On Windows the Clipboard is a bit more generic in how it operates - even if 
>> the MIME type mismatches, the Clipboard will accept any object and then 
>> return it. GTK is less generic in this regard (at least our Glass 
>> implementation) so for cases like text it requires us to fetch the String 
>> contents and set those directly onto the Clipboard.
>> 
>> Moreover, `ClipboardContent` is simply an extension of `HashMap` which 
>> exposes `put()` and lets us assign whatever object we want to whatever MIME 
>> type we want. As such, if we follow the example code from the JDK issue, we 
>> would try to fetch String contents from something that is not a String, 
>> causing SIGSEGV.
>> 
>> Fix was done by type-checking incoming `ClipboardContent` data. I saw that 
>> this can also happen in other content types than text, so I guarded those as 
>> well. If types are not what we expect them to be, the attempt to update the 
>> System Clipboard is silently discarded and the crash is avoided. According 
>> to my manual testing, as long as data types are correct everything seems to 
>> work fine.
>> 
>> As a side-note, this also shows there is discrepancy in how `Clipboard` 
>> operates between platforms. We should unify that behavior, but that is a 
>> larger task which will be solved under 
>> [JDK-8373090](https://bugs.openjdk.org/browse/JDK-8373090).
>
> Lukasz Kostyra has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Review: Move jstring cast

FYI: I've added a Clipboard page to the standalone monkey tester
https://github.com/andy-goryachev-oracle/MonkeyTest

with a bunch of canned options for data format and data values for testing.
Feel free to add (or ask me to add) missing combinations.

<img width="1274" height="477" alt="Screenshot 2025-12-08 at 10 58 42" 
src="https://github.com/user-attachments/assets/9afe5b26-5ad4-4cda-b6f4-0b3709e8330f";
 />

-------------

PR Comment: https://git.openjdk.org/jfx/pull/1999#issuecomment-3628583197

Reply via email to