Skip to content

Commit 64cf7b2

Browse files
committed
Fix int truncation of read length in shmop_read()
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(). Closes GH-22425
1 parent 86d78cc commit 64cf7b2

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

‎ext/shmop/shmop.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ PHP_FUNCTION(shmop_read)
224224
zend_long start, count;
225225
php_shmop *shmop;
226226
char *startaddr;
227-
int bytes;
228227
zend_string *return_string;
229228

230229
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oll", &shmid, shmop_ce, &start, &count) == FAILURE) {
@@ -244,7 +243,7 @@ PHP_FUNCTION(shmop_read)
244243
}
245244

246245
startaddr = shmop->addr + start;
247-
bytes = count ? count : shmop->size - start;
246+
zend_long bytes = count ? count : shmop->size - start;
248247

249248
return_string = zend_string_init(startaddr, bytes, 0);
250249

0 commit comments

Comments
 (0)