From 32678f955dec58b87f0589f302dae963e68e823e Mon Sep 17 00:00:00 2001 From: Affan Ziya Date: Tue, 3 Nov 2026 14:49:45 +0530 Subject: [PATCH] ly common BUGFIX reject overlong 4-byte UTF-8 sequences ly_getutf8() accepted 4-byte sequences decoding to 0x1000 - 0xFFFF, which are overlong forms of 3-byte characters, including the UTF-16 surrogates rejected by the 3-byte branch. The XML and JSON parsers use it to check values that are then stored with is_utf8 set, so these sequences were accepted and printed back verbatim, while ly_checkutf8() used for the other inputs rejects them. --- src/ly_common.c | 2 +- tests/utests/types/string.c | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/ly_common.c b/src/ly_common.c index 88aeba9f1..f1ed08e68 100644 --- a/src/ly_common.c +++ b/src/ly_common.c @@ -1386,7 +1386,7 @@ ly_getutf8(const char **input, uint32_t *utf8_char, uint32_t *bytes_read) c = (c << 6) | (aux & 0x3f); } - if ((c < 0x1000) || (c > 0x10ffff)) { + if ((c < 0x10000) || (c > 0x10ffff)) { goto error; } } else { diff --git a/tests/utests/types/string.c b/tests/utests/types/string.c index 50c0199b9..3fcde6529 100644 --- a/tests/utests/types/string.c +++ b/tests/utests/types/string.c @@ -742,6 +742,11 @@ test_data_xml(void **state) CHECK_LOG_CTX("Entity reference \"&text;