Skip to content

Conversation

akshatnehra
Copy link

Description

The SHOW CREATE LIBRARY command produces an incorrect hexadecimal representation of binary libraries on x86_64 architectures. On x86_64 platforms (where char is signed by default), the command inserts erroneous "FFFFFF" patterns before each byte with the high bit set, resulting in an invalid and bloated hex representation.

For example, on x86_64:
AS 0x3872FFFFFFD3FFFFFFBBFFFFFFA66A27FFFFFFA9FFFFFFA34F3834FFFFFFF3FFFFFF82FFFFFFBC1A7360FFFFFFD3FFFFFFBA0C5A7761FFFFFFE5FFFFFFE67A7B

While on AArch64:
AS 0x3872D3BBA66A27A9A34F3834F382BC1A7360D3BA0C5A7761E5E67A7B

The AArch64 representation is actually correct, as each byte is properly represented by exactly 2 hex digits, which is the standard way to represent binary data in hexadecimal format. 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.

This inconsistency causes test failures across different architectures and produces misleading, non-standard hexadecimal representations.

How to recreate the issue

Run the MySQL Test Run (MTR) test main.sp-library-binary on both x86_64 and AArch64 architectures:

[ 50%] main.sp-library-binary                    [ fail ]
        Test ended at 2025-09-02 20:34:16

CURRENT_TEST: main.sp-library-binary
--- /quick-mysql-build/mysql-server/mysql-test/r/sp-library-binary.result	2025-09-02 23:18:41.432449980 +0300
+++ /quick-mysql-build/build/mysql-test/var/log/sp-library-binary.reject	2025-09-02 23:34:14.844343433 +0300
@@ -44,7 +44,7 @@
 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

The test fails on AArch64 because it expects the incorrect x86_64 representation with "FFFFFF" patterns, but AArch64 correctly produces a standard hex representation.

Fix

  • Prevent sign extension on all platforms by using a bit mask to isolate only the relevant 8 bits of each byte:
    This approach masks off the higher bits with & 0xFF, preventing sign extension regardless of platform. It would produce the more compact and correct representation (matching current AArch64 behavior) on all architectures.

  • Update sp-library-binary.result file to match the correct behavior.

Testing

I have tested this fix on both x86_64 and AArch64 platforms and with the fix applied, both platforms produce identical, correct output.


This contribution is under the OCA signed by Amazon and covering submissions to the MySQL project.

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-oca-bot
Copy link

Hi, thank you for submitting this pull request. In order to consider your code we need you to sign the Oracle Contribution Agreement (OCA). Please review the details and follow the instructions at https://oca.opensource.oracle.com/
Please make sure to include your MySQL bug system user (email) in the returned form.
Thanks

@akshatnehra
Copy link
Author

This contribution is under the OCA signed by Amazon and covering submissions to the MySQL project.

@mysql-admin
Copy link

Hi @akshatnehra,
We have not yet received a confirmation from Amazon that you are included in the company OCA (we asked twice).
Please ask your side to confirm and contact/reply to emails from lenka.kasparova@oracle.com

Thanks for contributing to MySQL
==Omer

@mysql-oca-bot
Copy link

Hi, thank you for your contribution. Please confirm this code is submitted under the terms of the OCA (Oracle's Contribution Agreement) you have previously signed by cutting and pasting the following text as a comment:
"I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it."
Thanks

@akshatnehra
Copy link
Author

I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

@mysql-oca-bot
Copy link

Hi, thank you for your contribution. Your code has been assigned to an internal queue. Please follow
bug http://bugs.mysql.com/bug.php?id=118927 for updates.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants