From d03517ed08e1cec028573060ddd6d003fcf2eb5c Mon Sep 17 00:00:00 2001 From: Akshat Nehra Date: Tue, 2 Sep 2025 21:43:00 +0000 Subject: [PATCH] Bug#118927 Fix incorrect hex representation in SHOW CREATE LIBRARY This commit fixes the incorrect hexadecimal representation of binary libraries in SHOW CREATE LIBRARY output. The issue produces malformed hex literals where some bytes are incorrectly expanded with "FFFFFF" patterns, violating the standard convention that each byte should be represented by exactly 2 hex digits. For example, a binary library would incorrectly display as: 0x3872FFFFFFD3FFFFFFBBFFFFFFA6... Instead of the correct standard representation: 0x3872D3BBA66A27A9... This incorrect representation produces bloated output that violates universal hexadecimal formatting conventions. On x86_64 (where char is signed by default), negative byte values undergo sign extension, resulting in "FFFFFF" patterns in the hex representation. On AArch64 (where char is unsigned by default), these patterns are absent. The fix: - Modifies the binary_to_hex function to mask each byte value with & 0xFF, ensuring each byte is properly represented with exactly 2 hex digits - Updates the sp-library-binary.result test file to reflect the corrected hex representation This contribution is under the OCA signed by Amazon and covering submissions to the MySQL project. --- mysql-test/r/sp-library-binary.result | 2 +- sql/sp.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/sp-library-binary.result b/mysql-test/r/sp-library-binary.result index e2ba95800cf7..0e76d2883a17 100644 --- a/mysql-test/r/sp-library-binary.result +++ b/mysql-test/r/sp-library-binary.result @@ -44,7 +44,7 @@ Library sql_mode Create Library binary_library_binary ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION CREATE LIBRARY `binary_library_binary` COMMENT 'A binary library stored in binary encoding' LANGUAGE WASM -AS 0x3872FFFFFFD3FFFFFFBBFFFFFFA66A27FFFFFFA9FFFFFFA34F3834FFFFFFF3FFFFFF82FFFFFFBC1A7360FFFFFFD3FFFFFFBA0C5A7761FFFFFFE5FFFFFFE67A7B +AS 0x3872D3BBA66A27A9A34F3834F382BC1A7360D3BA0C5A7761E5E67A7B # Negative tests: CREATE LIBRARY binary_library_binary_neg LANGUAGE WASM AS _binary b'01210'; diff --git a/sql/sp.cc b/sql/sp.cc index ec9d07bdedf3..e5b17546ea25 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -2543,7 +2543,7 @@ static std::string binary_to_hex(std::string_view input) { std::stringstream ss; ss << std::hex << std::uppercase << std::setfill('0'); for (char i : input) { - ss << std::setw(2) << static_cast(i); + ss << std::setw(2) << (static_cast(i) & 0xFF); } return ss.str(); }