Bug#118927 Fix incorrect hex representation in SHOW CREATE LIBRARY #628
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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.