From 18aaed63b9b3f1908b14813096e1d1ca3520538d Mon Sep 17 00:00:00 2001 From: Damian Gryski Date: Fri, 15 Oct 2021 10:17:34 -0700 Subject: [PATCH] src/runtime: add another set of invalid unicode runes to encodeUTF8() --- src/runtime/string.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/runtime/string.go b/src/runtime/string.go index c1c12cc7..74e16e02 100644 --- a/src/runtime/string.go +++ b/src/runtime/string.go @@ -160,6 +160,9 @@ func encodeUTF8(x rune) ([4]byte, uintptr) { b1 := 0xc0 | byte(x>>6) b2 := 0x80 | byte(x&0x3f) return [4]byte{b1, b2, 0, 0}, 2 + case 0xd800 <= x && x <= 0xdfff: + // utf-16 surrogates are replaced with "invalid code point" + return [4]byte{0xef, 0xbf, 0xbd, 0}, 3 case x <= 0xffff: b1 := 0xe0 | byte(x>>12) b2 := 0x80 | byte((x>>6)&0x3f)