51def read_utf16(buf, off, max_char):
52 if off
is None or off < 0
or off >= len(buf):
54 raw = buf[off : off + max_char * 2]
55 end = raw.find(b
"\x00\x00")
57 raw = raw[: end + (end & 1)]
59 return raw.decode(
"utf-16-le",
"ignore").rstrip(
"\x00")
60 except (UnicodeDecodeError, ValueError):