Skip to content

Fix GH-18114: pdo lazy object crash #18116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ext/pdo/pdo_stmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ static void pdo_get_lazy_object(pdo_stmt_t *stmt, zval *return_value) /* {{{ */
pdo_row_t *row = zend_object_alloc(sizeof(pdo_row_t), pdo_row_ce);
row->stmt = stmt;
zend_object_std_init(&row->std, pdo_row_ce);
object_properties_init(&row->std, pdo_row_ce);
stmt->lazy_object_ref = &row->std;
GC_ADDREF(&stmt->std);
GC_DELREF(&row->std);
Expand Down Expand Up @@ -2405,6 +2406,7 @@ static zend_object *pdo_row_new(zend_class_entry *ce)
{
pdo_row_t *row = zend_object_alloc(sizeof(pdo_row_t), ce);
zend_object_std_init(&row->std, ce);
object_properties_init(&row->std, ce);

return &row->std;
}
Expand Down
17 changes: 17 additions & 0 deletions ext/pdo_sqlite/tests/gh18114.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
GH-18114 (pdo lazy object crash)
--EXTENSIONS--
pdo_sqlite
--XLEAK--
See https://github.com/php/php-src/issues/18114#issuecomment-2738069692, will be fixed in a later PR on lower branches
--FILE--
<?php
$db = new PDO('sqlite::memory:');
$x = $db->query('select 1 as queryString');
foreach ($x->fetch(PDO::FETCH_LAZY) as $entry) {
var_dump($entry);
}
echo "Done\n";
?>
--EXPECT--
Done
Loading