Skip to content

PCRE pattern cache crashes process in wrapper stream_close called after shutdown #15064

Closed
@nicolaslegland

Description

@nicolaslegland

Description

The following code:

<?php

\preg_replace('/pattern/', 'replace', 'subject');

class wrapper
{
	public function stream_open($path, $mode, $options, &$opened_path)
	{
		echo __METHOD__.PHP_EOL;
		return true;
	}

	public function stream_close()
	{
		echo __METHOD__.PHP_EOL;
		\preg_replace('/pattern/', 'replace', 'subject');
	}

	public $context;
}

echo \php_sapi_name().PHP_EOL;

\stream_wrapper_register('wrapper', 'wrapper');
$handle = \fopen('wrapper://', 'rb');

Resulted in this output (PHP 8.3.9, 8.3.0, 8.2.0, 7.4.0):

cli
wrapper::stream_open

ERRORLEVEL -1073741819 (0xC0000005) Access violation

Resulted in this output (PHP 8.1.0, 8.0.0):

cli
wrapper::stream_open

ERRORLEVEL -1073740791 (0xC0000409) Stack buffer overrun

But I expected this output instead:

cli
wrapper::stream_open
wrapper::stream_close

ERRORLEVEL 0

PHP Version

PHP 8.3.9, 8.3.0, 8.2.0, 8.1.0, 8.0.0, 7.4.0

Operating System

Windows 11 Pro, Build 22621.ni_release.220506-1250

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions