From d09441ca03e399fe641da88624c8ea0476967187 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Thu, 13 Jul 2023 12:22:07 -0400 Subject: [PATCH] fs: fix WTF-8 decoding issue (#4092) We forgot to mask off the high bits from the first byte, so we ended up always failing the subsequent range check. Refs: #2970 Fixes: https://github.com/nodejs/node/issues/48673 --- src/win/fs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/win/fs.c b/src/win/fs.c index fc209c54..4fc13b04 100644 --- a/src/win/fs.c +++ b/src/win/fs.c @@ -176,9 +176,11 @@ static int32_t fs__decode_wtf8_char(const char** input) { if ((b4 & 0xC0) != 0x80) return -1; /* invalid: not a continuation byte */ code_point = (code_point << 6) | (b4 & 0x3F); - if (b1 <= 0xF4) + if (b1 <= 0xF4) { + code_point &= 0x1FFFFF; if (code_point <= 0x10FFFF) return code_point; /* four-byte character */ + } /* code point too large */ return -1;