From 34d8da24e119d31bd0484d7f27c000e11ff850cc Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Wed, 19 Mar 2025 22:43:57 +0100 Subject: [PATCH 1/2] Fix GH-18114: pdo lazy object crash Since 0537968, the properties are no longer initialized. So we call object_properties_init to handle that correctly. Lower branches have a memory leak, but that requires a separate fix. --- ext/pdo/pdo_stmt.c | 2 ++ ext/pdo_sqlite/tests/gh18114.phpt | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 ext/pdo_sqlite/tests/gh18114.phpt diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index 0ffded87c08a0..9d3cc1536acc0 100644 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -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); @@ -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, pdo_row_ce); return &row->std; } diff --git a/ext/pdo_sqlite/tests/gh18114.phpt b/ext/pdo_sqlite/tests/gh18114.phpt new file mode 100644 index 0000000000000..6155bceeae9ba --- /dev/null +++ b/ext/pdo_sqlite/tests/gh18114.phpt @@ -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-- +query('select 1 as queryString'); +foreach ($x->fetch(PDO::FETCH_LAZY) as $entry) { + var_dump($entry); +} +echo "Done\n"; +?> +--EXPECT-- +Done From f53f73dffaf347e7550a92008e82d2d08fd21d9e Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Wed, 19 Mar 2025 22:56:56 +0100 Subject: [PATCH 2/2] use ce --- ext/pdo/pdo_stmt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index 9d3cc1536acc0..58924b0dfae42 100644 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -2406,7 +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, pdo_row_ce); + object_properties_init(&row->std, ce); return &row->std; }