[pecl-database-pdo_oci] main: Fix crash when re-executing a statement after closeCursor()

From: Date: Thu, 29 Oct 2026 12:32:07 +0000
Subject: [pecl-database-pdo_oci] main: Fix crash when re-executing a statement after closeCursor()
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-28711@lists.php.net to get a copy of this message
Author: Ilia Alshanetsky (iliaal) Date: 2026-10-16T15:40:47-04:00 Commit: https://github.com/php/pecl-database-pdo_oci/commit/c1c07ac4bc0cb641a1ac04f7a46a365c987dc818 Raw diff: https://github.com/php/pecl-database-pdo_oci/commit/c1c07ac4bc0cb641a1ac04f7a46a365c987dc818.diff Fix crash when re-executing a statement after closeCursor() closeCursor() clears stmt->executed, so the next execute() reallocates S->cols, but PDO core keeps its column descriptions and skips describing them again. The OCI defines then keep writing into the freed buffers and the next fetch crashes. Drop PDO's column descriptions when reallocating so they are described into the new buffers. The same path is reached on any re-execute with PHP 8.4.27RC1, 8.5.12RC1 and 8.6.0RC3, see #44. Changed paths: A tests/pdo_oci_closecursor_reexecute.phpt M oci_statement.c M package.xml Diff: diff --git a/oci_statement.c b/oci_statement.c index 5f8f062..47f8db2 100644 --- a/oci_statement.c +++ b/oci_statement.c @@ -172,6 +172,8 @@ static int oci_stmt_execute(pdo_stmt_t *stmt) /* {{{ */ STMT_CALL_MSG(OCIAttrGet, "ATTR_PARAM_COUNT", (S->stmt, OCI_HTYPE_STMT, &colcount, 0, OCI_ATTR_PARAM_COUNT, S->err)); + /* drop PDO's column descriptions so it re-describes them into the new S->cols */ + php_pdo_stmt_set_column_count(stmt, 0); stmt->column_count = (int)colcount; if (S->cols) { diff --git a/package.xml b/package.xml index cc58062..f9f88ff 100644 --- a/package.xml +++ b/package.xml @@ -103,6 +103,7 @@ Oracle&apos;s standard cross-version connectivity applies. For example, PHP PDO <file name="pdo_oci_bind_bool.phpt" role="test" /> <file name="pdo_oci_bind_input_output.phpt" role="test" /> <file name="pdo_oci_class_constants.phpt" role="test" /> + <file name="pdo_oci_closecursor_reexecute.phpt" role="test" /> <file name="pdo_oci_debugdumpparams.phpt" role="test" /> <file name="pdo_oci_fread_1.phpt" role="test" /> <file name="pdo_oci_phpinfo.phpt" role="test" /> diff --git a/tests/pdo_oci_closecursor_reexecute.phpt b/tests/pdo_oci_closecursor_reexecute.phpt new file mode 100644 index 0000000..e99efa8 --- /dev/null +++ b/tests/pdo_oci_closecursor_reexecute.phpt @@ -0,0 +1,60 @@ +--TEST-- +PDO_OCI: Re-executing a statement after closeCursor() +--EXTENSIONS-- +pdo +pdo_oci +--SKIPIF-- +<?php +require(getenv('PDO_TEST_DIR').'/pdo_test.inc'); +PDOTest::skip(); +?> +--FILE-- +<?php + +require_once(getenv('PDO_TEST_DIR').'/pdo_test.inc'); + +$dbh = PDOTest::factory(); +$stmt = $dbh->prepare("SELECT 'A' AS id, 'B' AS val FROM dual"); + +$stmt->execute(); +echo "first: "; +var_dump($stmt->fetchAll(PDO::FETCH_NUM)); + +$stmt->closeCursor(); +$stmt->execute(); +echo "after closeCursor: "; +var_dump($stmt->fetchAll(PDO::FETCH_NUM)); + +$stmt->execute(); +echo "after re-execute: "; +var_dump($stmt->fetchAll(PDO::FETCH_NUM)); + +?> +--EXPECT-- +first: array(1) { + [0]=> + array(2) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + } +} +after closeCursor: array(1) { + [0]=> + array(2) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + } +} +after re-execute: array(1) { + [0]=> + array(2) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + } +}

« previous php.pecl.cvs (#28711) next »