RFR: 8269630: Bad clipboard data causes JVM to crash [v2]
Kevin Rushforth
kcr at openjdk.org
Tue Jan 6 17:29:49 UTC 2026
On Mon, 8 Dec 2025 15:11:08 GMT, Lukasz Kostyra <lkostyra at openjdk.org> 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
The code changes look good. I verified on Ubuntu 24.04 that the test program attached to JBS crashes without the fix and works with the fix.
-------------
Marked as reviewed by kcr (Lead).
PR Review: https://git.openjdk.org/jfx/pull/1999#pullrequestreview-3631799700
More information about the openjfx-dev
mailing list