From 27683f3ddca4160ff39fe99639a21da74fd68f50 Mon Sep 17 00:00:00 2001 From: Junyu Long <877730493@qq.com> Date: Tue, 6 Aug 2024 11:39:43 +0800 Subject: [PATCH] winhandler: catch overflow exception. --- .../java/com/winlator/winhandler/WinHandler.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/winlator/winhandler/WinHandler.java b/app/src/main/java/com/winlator/winhandler/WinHandler.java index f7ac5bf0..533dcf95 100644 --- a/app/src/main/java/com/winlator/winhandler/WinHandler.java +++ b/app/src/main/java/com/winlator/winhandler/WinHandler.java @@ -169,11 +169,17 @@ public void bringToFront(final String processName) { public void bringToFront(final String processName, final long handle) { addAction(() -> { sendData.rewind(); - sendData.put(RequestCodes.BRING_TO_FRONT); - byte[] bytes = processName.getBytes(); - sendData.putInt(bytes.length); - sendData.put(bytes); - sendData.putLong(handle); + try { + sendData.put(RequestCodes.BRING_TO_FRONT); + byte[] bytes = processName.getBytes(); + sendData.putInt(bytes.length); + // FIXME: Chinese and Japanese got from winhandler.exe are broken, and they cause overflow. + sendData.put(bytes); + sendData.putLong(handle); + } catch (java.nio.BufferOverflowException e) { + e.printStackTrace(); + sendData.rewind(); + } sendPacket(CLIENT_PORT); }); }