Fix int truncation of read length in shmop_read()#22425
Open
iliaal wants to merge 1 commit into
Open
Conversation
shmop_read() held the read length in an int while count and shmop->size are zend_long and the bounds checks above validate against the full 64-bit size. On a shared-memory segment larger than INT_MAX a read whose length sets the int sign bit was sign-extended into the size_t length argument of zend_string_init(), requesting a near-SIZE_MAX allocation; other truncated lengths silently returned a wrong-sized string. Hold the length in a zend_long, matching the zend_long writesize already used in shmop_write().
Contributor
|
Looks good but I am not an expert in this. cc @Girgias if she might offer some help :) |
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.
shmop_read() held the read length in an int while count and shmop->size are zend_long and the bounds checks validate against the full 64-bit size. On a shared-memory segment larger than INT_MAX, a length that sets the int sign bit was sign-extended into the size_t argument of zend_string_init(), requesting a near-SIZE_MAX allocation; other truncated lengths returned a wrong-sized string. Hold the length in a zend_long, matching the zend_long writesize already used in shmop_write(). Triggering needs a >2GB segment, so there is no portable red/green test; the fix is a type correction with no behavioral change below INT_MAX.