Skip to content

Commit d09441c

Browse files
authored
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: nodejs/node#48673
1 parent 50b53cb commit d09441c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/win/fs.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,11 @@ static int32_t fs__decode_wtf8_char(const char** input) {
176176
if ((b4 & 0xC0) != 0x80)
177177
return -1; /* invalid: not a continuation byte */
178178
code_point = (code_point << 6) | (b4 & 0x3F);
179-
if (b1 <= 0xF4)
179+
if (b1 <= 0xF4) {
180+
code_point &= 0x1FFFFF;
180181
if (code_point <= 0x10FFFF)
181182
return code_point; /* four-byte character */
183+
}
182184

183185
/* code point too large */
184186
return -1;

0 commit comments

Comments
 (0)