opcache.file_cache: segfault or wrong function for functions loaded with dl()

未关闭
#25,296 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
c, php

调研方向

Start with the ZEND_INIT_FCALL offset handling in zend_file_cache.c and review the change identified as d6541df63, along with related issue GH-24661. Reproduce the supplied dl() and OPcache file cache commands using the example scripts, then trace how functions added by the extension affect cached calls. Done means repeated runs call dl_test_test2() and print "Hello World" without a crash or calling a different function.

由索引模型根据 Issue 内容生成。

描述

Description

Quoted text written with an LLM and checked by a human developer.

A script in the file cache can crash or call the wrong function if it calls a function loaded with dl(), and that function has a different position in the function table on a later run.

d6541df63 (GH-24664) removed the reset of the ZEND_INIT_FCALL offset from zend_file_cache.c. The old comment said the reset could go once system ID validation was in place. The system ID is finalized at startup, so it does not cover functions added later by dl().

main.php:

<?php
if (isset($argv[1])) {
    function a() {}
    function b() {}
}
dl('dl_test');
include __DIR__ . '/call.php';

call.php:

<?php
var_dump(dl_test_test2());

With dl_test built as a shared extension:

PHP="php -d opcache.enable_cli=1 -d opcache.file_cache=/tmp/fc -d opcache.file_cache_only=1 -d opcache.file_update_protection=0"
$PHP main.php x
$PHP main.php

Resulted in this output:

string(11) "Hello World"
Segmentation fault

But I expected this output instead:

string(11) "Hello World"
string(11) "Hello World"

With only function a() {}, the second run calls a different function:

Fatal error: Uncaught ArgumentCountError: dl_test_frameless() expects exactly 1 argument, 0 given

Tested on debug and release builds of PHP-8.4 at 3ace94211. An earlier build at 2f6fd1167, without d6541df63, prints the expected output. The reset is also gone from the sources of php-8.4.28RC1, php-8.5.13RC1 and php-8.6.0RC5, which I did not build.

Related: GH-24661

PHP Version
PHP 8.4.28-dev (3ace94211)
Operating System

Ubuntu 26.04

主要语言
C
星标
41.8k
派生
8.5k
平均合并
2 天 12 小时
30 天内合并 PR
137

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

php/php-src 的其他 Issue

查看 php/php-src 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。