PDOStatement::$queryString "readonly" is not properly implemented
オープン
Bug
Extension: pdo (core)
Status: Verified
- 主要言語
- C
- スター
- 40.4k
- フォーク
- 8.2k
- 平均マージ
- 2日 13時間
- マージ済み PR(30日)
- 96
説明
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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、リンク先の行にある ext/pdo/pdo_stmt.c を読み、issue の再現を実行してください。PDOStatement::$queryString への繰り返しの代入が readonly チェックを回避せず、期待される Error を生成するようになれば完了です。この問題にはすでに対応するオープンな pull request があります。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- c, php
- 領域
- databases
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 30/100