Skip to content

Fix int truncation of read length in shmop_read()#22425

Open
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:shmop-read-int-truncation
Open

Fix int truncation of read length in shmop_read()#22425
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:shmop-read-int-truncation

Conversation

@iliaal

@iliaal iliaal commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

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.

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().
@LamentXU123

Copy link
Copy Markdown
Contributor

Looks good but I am not an expert in this. cc @Girgias if she might offer some help :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants