From f8c867b78f8c3ea8fe97bb97a5fa4f175bb44cb5 Mon Sep 17 00:00:00 2001 From: Yi LIU Date: Mon, 16 Feb 2026 23:48:44 +0800 Subject: [PATCH] Fix signed char arithmetic shift in name escaping In WasmBinaryReader::escape(), the loop variable 'char c' is signed on most platforms (x86, ARM). For bytes >= 0x80, 'c >> 4' performs an arithmetic right shift, producing negative values that formatNibble converts to wrong hex characters (e.g., 0xFF gives '/' instead of 'f'). Cast to unsigned char before shifting to ensure logical right shift. --- src/wasm/wasm-binary.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 23077d236a9..d89e1688677 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -5136,8 +5136,8 @@ Name WasmBinaryReader::escape(Name name) { } // replace non-idchar with `\xx` escape escaped.push_back('\\'); - escaped.push_back(formatNibble(c >> 4)); - escaped.push_back(formatNibble(c & 15)); + escaped.push_back(formatNibble((unsigned char)c >> 4)); + escaped.push_back(formatNibble((unsigned char)c & 15)); } return escaped; }