RFR: 8304441: [macos] Crash when putting invalid unicode char on clipboard

Kevin Rushforth kcr at openjdk.org
Tue Mar 28 15:16:35 UTC 2023


A malformed unicode string containing only half of a surrogate pair (either a high or low surrogate without the other half) will cause a native exception in the macOS `NSPasteboardItem setString:forType:` method. This uncaught exception will terminate (crash) the application.

The fix is to validate the string before calling `setString:forType:`. I also added a try / catch that logs a warning, so that if we ever run into other exceptions, they won't be fatal.

I added an automated test that fails on macOS without the fix and passes with the fix. The test is run on other platforms as well, and passes both before and after the fix.

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

Commit messages:
 - fix whitespace
 - 8304441: [macos] Crash when putting invalid unicode char on clipboard

Changes: https://git.openjdk.org/jfx/pull/1074/files
 Webrev: https://webrevs.openjdk.org/?repo=jfx&pr=1074&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8304441
  Stats: 115 lines in 2 files changed: 113 ins; 0 del; 2 mod
  Patch: https://git.openjdk.org/jfx/pull/1074.diff
  Fetch: git fetch https://git.openjdk.org/jfx.git pull/1074/head:pull/1074

PR: https://git.openjdk.org/jfx/pull/1074


More information about the openjfx-dev mailing list