From 914b96c1bddd0738464c043cccbbac14fc94b955 Mon Sep 17 00:00:00 2001 From: qmuntal Date: Thu, 1 Feb 2024 15:05:25 +0100 Subject: [PATCH] windows: support ill-formed UTF-16 in UTF16PtrToString UTF16PtrToString does not support ill-formed UTF-16 because it uses utf16.Decode, which expects well-formed UTF-16. This CL updates the UTF16PtrToString implementation to use UTF16ToString instead of utf16.Decode, which supports ill-formed UTF-16 since go1.21 via syscall.UTF16ToString. Change-Id: Ifb72b6d38a8c08ad90ec6a47eed05fc3739500a1 Reviewed-on: https://go-review.googlesource.com/c/sys/+/560355 LUCI-TryBot-Result: Go LUCI Reviewed-by: Bryan Mills Reviewed-by: Michael Knyszek --- windows/syscall_windows.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/windows/syscall_windows.go b/windows/syscall_windows.go index ffb8708c..6395a031 100644 --- a/windows/syscall_windows.go +++ b/windows/syscall_windows.go @@ -125,8 +125,7 @@ func UTF16PtrToString(p *uint16) string { for ptr := unsafe.Pointer(p); *(*uint16)(ptr) != 0; n++ { ptr = unsafe.Pointer(uintptr(ptr) + unsafe.Sizeof(*p)) } - - return string(utf16.Decode(unsafe.Slice(p, n))) + return UTF16ToString(unsafe.Slice(p, n)) } func Getpagesize() int { return 4096 }