PDOStatement::$queryString "readonly" is not properly implemented
未关闭
Bug
Extension: pdo (core)
Status: Verified
- 主要语言
- C
- 星标
- 40.4k
- 派生
- 8.2k
- 平均合并
- 2 天 15 小时
- 30 天内合并 PR
- 103
描述
Description
The following code:
<?php
$stmt = new PDOStatement();
var_dump($stmt);
for($i=0;$i<10;$i++)
$stmt->queryString = (string) $i;
var_dump($stmt);
Resulted in this output:
object(PDOStatement)#1 (0) {
["queryString"]=>
uninitialized(string)
}
object(PDOStatement)#1 (1) {
["queryString"]=>
string(1) "9"
}
But I expected this output instead:
object(PDOStatement)#1 (0) {
["queryString"]=>
uninitialized(string)
}
Fatal error: Uncaught Error: Property queryString is read only in x.php:5
The reason this happens is because the following code is wrong:
https://github.com/php/php-src/blob/209e0d6ad29b1f49982c58088aadd9d1ad86a162/ext/pdo/pdo_stmt.c#L2008-L2014
The second loop iteration just reuses the cache slot and won't go through the write handler, bypassing the fake readonly check.
Either this should be relaxed or be fixed (i.e. "real readonly").
PHP Version
8.3+
Operating System
No response
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先阅读链接行中的 ext/pdo/pdo_stmt.c,并运行 issue 中的复现。完成的标志是,对 PDOStatement::$queryString 的重复赋值不再绕过 readonly 检查并产生预期的 Error;已有一个开放的 pull request 处理此问题。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- c, php
- 领域
- databases
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 30/100