Fix GH-18173: ext/hash relies on implementation-defined malloc alignment#21668
Open
iliaal wants to merge 1 commit intophp:PHP-8.4from
Open
Fix GH-18173: ext/hash relies on implementation-defined malloc alignment#21668iliaal wants to merge 1 commit intophp:PHP-8.4from
iliaal wants to merge 1 commit intophp:PHP-8.4from
Conversation
…gnment XXH3_state_t requires 64-byte alignment for its acc, customSecret, and buffer members. php_hash_alloc_context() used ecalloc() which only guarantees alignof(max_align_t) alignment -- typically 16 bytes on x86_64. When heap layout broke that assumption, xxhash's aligned loads would segfault. Add a context_align field to php_hash_ops. When set, php_hash_alloc_context() over-allocates and manually aligns the returned pointer, storing the offset for php_hash_free_context() to recover the original allocation.
b6d6106 to
1db4b19
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
XXH3_state_trequires 64-byte alignment for its internal buffers.php_hash_alloc_context()usedecalloc(), which only guaranteesalignof(max_align_t)(16 bytes on x86_64). When the allocator returned a pointer that wasn't 64-byte aligned, xxhash's aligned loads segfaulted.Adds a
context_alignfield tophp_hash_ops. When non-zero,php_hash_alloc_context()over-allocates and manually aligns the pointer, storing the offset byte sophp_hash_free_context()can recover the original allocation. Set to 64 for xxh3 and xxh128.Reproduce with
ZEND_MM_DEBUG=padding=8 TESTS=ext/hash make test.