Skip to content

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

Closed
iliaal wants to merge 1 commit into
PHP-8.4from
shmop-read-int-truncation
Closed

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

Conversation

@iliaal

@iliaal iliaal commented Jun 21, 2026

Copy link
Copy Markdown
Owner

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

iliaal commented Jun 24, 2026

Copy link
Copy Markdown
Owner Author

Promoted upstream: php#22425

@iliaal iliaal closed this Jun 24, 2026
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.

1 participant