From c6b67af39011e040267bff20deaeb254feb869ad Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 19 Nov 2024 19:09:03 +0100 Subject: [PATCH] unix,win: fix off-by-one in uv_wtf8_to_utf16() (#4609) uv_wtf8_length_as_utf16() checks if codepoints are > 0xFFFF (to see if it should be encoded as a surrogate pair), therefore uv_wtf8_to_utf16() should too. Instead it checked > 0x1000. Harmonize the checks. Fixes: https://github.com/nodejs/node/issues/55914 --- src/idna.c | 2 +- test/test-idna.c | 12 ++++++++++++ test/test-list.h | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/idna.c b/src/idna.c index efc5f283..5fcaf64c 100644 --- a/src/idna.c +++ b/src/idna.c @@ -393,7 +393,7 @@ void uv_wtf8_to_utf16(const char* source_ptr, code_point = uv__wtf8_decode1(&source_ptr); /* uv_wtf8_length_as_utf16 should have been called and checked first. */ assert(code_point >= 0); - if (code_point > 0x10000) { + if (code_point > 0xFFFF) { assert(code_point < 0x10FFFF); *w_target++ = (((code_point - 0x10000) >> 10) + 0xD800); *w_target++ = ((code_point - 0x10000) & 0x3FF) + 0xDC00; diff --git a/test/test-idna.c b/test/test-idna.c index 28f9eaaa..4a165573 100644 --- a/test/test-idna.c +++ b/test/test-idna.c @@ -218,3 +218,15 @@ TEST_IMPL(idna_toascii) { #undef T #endif /* __MVS__ */ + +TEST_IMPL(wtf8) { + static const char input[] = "ᜄȺy𐞲:𞢢𘴇𐀀'¥3̞[