Mojira Archive
MC-168949

copy_to_clipboard crashes client when copying trailing high surrogate char

The bug

The client crashes when clicking on a text component with a copy_to_clipboard clickEvent which copies text with a high surrogate character.

Description: mouseClicked event handler

java.lang.StringIndexOutOfBoundsException: String index out of range: 1
	at java.lang.String.charAt(String.java:646)
	at org.lwjgl.system.MemoryUtil.encodeUTF8(MemoryUtil.java:1937)
	at org.lwjgl.system.MemoryUtil.memUTF8(MemoryUtil.java:1894)
	at cxc.a(SourceFile:28)
	at cxc.a(SourceFile:35)
	at dbj.a(SourceFile:442)
	at dfz.handleComponentClicked(SourceFile:308)
	at dey.mouseClicked(SourceFile:142)
	at dbm.b(SourceFile:86)
	at dbm$$Lambda$2099/777548434.run(Unknown Source)
	at dfz.wrapScreenError(SourceFile:447)
	at dbm.a(SourceFile:86)
	at dbm.c(SourceFile:150)
	at dbm$$Lambda$2098/2115270696.run(Unknown Source)
	at aip.execute(SourceFile:94)
	at dbm.b(SourceFile:150)
	at dbm$$Lambda$1492/1008774102.invoke(Unknown Source)
	at org.lwjgl.glfw.GLFWMouseButtonCallbackI.callback(GLFWMouseButtonCallbackI.java:36)
	at org.lwjgl.system.JNI.invokeV(Native Method)
	at org.lwjgl.glfw.GLFW.glfwPollEvents(GLFW.java:3101)
	at com.mojang.blaze3d.systems.RenderSystem.flipFrame(SourceFile:105)
	at cxu.e(SourceFile:301)
	at dbl.d(SourceFile:970)
	at dbl.b(SourceFile:585)
	at net.minecraft.client.main.Main.main(SourceFile:202)

How to reproduce

/tellraw @s {"text":"Click","clickEvent":{"action":"copy_to_clipboard","value":"\uD800"}}

Code analysis

Minecraft has to sanitize strings before usings LWJGL's MemoryUtil.memUTF8, see LWJGL issue 518:

So, when dealing with trusted text, use the LWJGL codecs. When not, the JDK's CharsetEncoder/CharsetDecoder can be used instead, configured with the appropriate behavior on invalid input.

Fixed

Marcono1234

[Mojang] Bartosz Bok

2019-12-27, 08:20 PM

2020-01-13, 02:04 PM

2020-01-13, 02:04 PM

1

0

Confirmed

Very Important

Crash

1.15.1

1.15.2 Pre-Release 1