php / php/php-src

PHP8.5: Opcache can crash in `do_implement_interface` when trait causes implicit `Stringable` interface addition

Đang mở
#23,567 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Bug Status: Needs Triage
Ngôn ngữ chính
C
Star
40.4k
Fork
8.1k
Merge trung bình
2 ngày 13 giờ
Pull request đã merge (30 ngày)
96

Mô tả

Description

Just expanding on the description a little, in the following conditions:

  • PHP8.5 is used (8.4 at least is not affected)
  • opcache.enable & opcache.enable_cli are enabled (This may not require enable_cli with other SAPIs, but my issue was on the CLI / this is where I have narrowed down the issue)
  • A trait exists which has a __toString method
  • A class uses the above trait without declaring it implements Stringable (the base class)
  • A sub-class in a different file extends the base class (regardless of if implements Stringable or not)

With the above conditions, then if you have:

  1. A process that runs for at least the time for the second/third steps)
  2. A process runs that loads the base class into opcache's shared memory
  3. A process runs that loads the file the sub-class is in is ran

The process in step 3 will crash with an exit code of -1073741819 (0xC0000005 - STATUS_ACCESS_VIOLATION).

The above process will also cause the crash if the long running process loads the base class into opcache's shared memory - the important points are that when step 3 happens there is a process that was running when the base class was loaded - it isn't relevant if it is the process that did the loading or not.

Full code for replicating:
Main file

<?php
$mode = $argv[1] ?? "";
if($mode === "hold"){
	\sleep(30);
	echo "hold ok\n";
	exit(0);
}
trait TestTrait{
	public function __toString() : string{
		return "testString";
	}
}

class TestBaseClass{
	use TestTrait;
}
switch($mode){
	case "base":
		echo "base ok\n";
		exit(0);
	case "sub":
		require __DIR__ . "/subclass.php";
		echo "sub ok\n";
		exit(0);
}

subclass.php:

<?php
class TestSubclass extends TestBaseClass{}

Commands to run (terminal one):

php -n -d opcache.enable=1 -d opcache.enable_cli=1 test.php hold

Commands to run (terminal two):

php -n -d opcache.enable=1 -d opcache.enable_cli=1 test.php base
echo %errorlevel%
php -n -d opcache.enable=1 -d opcache.enable_cli=1 test.php sub
echo %errorlevel%

Resulted in this output (terminal one):

hold ok

Resulted in this output (terminal two):

base ok
0

-1073741819

But I expected this output instead (terminal one):

hold ok

But I expected this output instead (terminal two):

base ok
0
sub ok
0
PHP Version
PHP 8.4.6 (cli) (built: Apr  9 2025 09:45:15) (ZTS Visual C++ 2022 x64)
Copyright (c) The PHP Group
Zend Engine v4.4.6, Copyright (c) Zend Technologies
Operating System

Windows 11 x64

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với main file và trình tái hiện subclass.php được cung cấp, sau đó chạy hai chuỗi lệnh Windows CLI với PHP 8.5 và Opcache được bật. Xác nhận rằng việc tải base class rồi đến subclass không còn kết thúc với STATUS_ACCESS_VIOLATION mà thay vào đó in “sub ok” với exit code 0; issue không nêu tên file triển khai hoặc test.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
php
Lĩnh vực
backend, performance
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Sôi nổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
55/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.