Skip to content

shmop Windows 11 crashes the process #14537

Closed
@EdmondDantes

Description

@EdmondDantes

Description

Description:
An attempt to allocate a memory block with the same key but a larger size after proper deallocation causes a memory violation and crashes the process.

The following code:

<?php
declare(strict_types=1);

$str = 'Hello World';

$shm_key = ftok(__FILE__, 'p');

$shm_id1 = shmop_open($shm_key, 'c', 0644, strlen($str));
shmop_delete($shm_id1);

$shm_id2 = shmop_open($shm_key, 'c', 0644, strlen($str) + 10);
                                                                   // ^ -- This is the difference

if ($shm_id2) {
    shmop_write($shm_id2, $str, 0);
}
else
    throw new RuntimeException("Couldn't create shared memory segment.");

Resulted in this output:

Warning: shmop_open(): Unable to attach or create shared memory segment "No error" in C:\work\ct\cluster\test.php on line 11
PHP Warning:  shmop_open(): Unable to attach or create shared memory segment "No error" in C:\work\ct\cluster\test.php on line 11

Process finished with exit code -1073741819 (0xC0000005)
// Memory crached

But I expected this output instead:

All should be OK

The same code on Unix has no issues

PHP Version

PHP 8.3.4

Operating System

Windows 11

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions