[LTP] [PATCH 01/15] ujson: Fix 4-byte UTF-8 sequence decoding

Andrea Cervesato andrea.cervesato@suse.de
Mon Oct 5 15:25:29 CEST 2026


From: Andrea Cervesato <andrea.cervesato@suse.com>

In ujson_utf8_next(), decoding 4-byte UTF-8 sequences read past the
byte boundary, verified the already-masked byte s2 instead of the
fourth byte s3, and failed to advance the string pointer correctly.
As a result, any 4-byte UTF-8 sequence was rejected and returned 0.

Fixes: c50a0e0751c8 ("libs: Vendor ujson library")
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 include/ujson_utf.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/ujson_utf.h b/include/ujson_utf.h
index 83fe8ab09..801a1fcb2 100644
--- a/include/ujson_utf.h
+++ b/include/ujson_utf.h
@@ -65,15 +65,15 @@ static inline uint32_t ujson_utf8_next(const char **str)
 	if (UJSON_UTF8_IS_3BYTE(s0))
 		return (s0 & 0x0f)<<12 | s1<<6 | s2;
 
-	(*str)++;
-
 	uint32_t s3 = *str[0];
 
-	if (!UJSON_UTF8_IS_NBYTE(s2))
+	if (!UJSON_UTF8_IS_NBYTE(s3))
 		return 0;
 
 	s3 &= UJSON_UTF8_NBYTE_MASK;
 
+	(*str)++;
+
 	if (UJSON_UTF8_IS_4BYTE(s0))
 		return (s0 & 0x07)<<18 | s1<<12 | s2<<6 | s3;
 

-- 
2.51.0



More information about the ltp mailing list