Skip to content

Fix GH-23756: crash when a collation callback closes the statement cursor - #23762

Open
lazerg wants to merge 1 commit into
php:PHP-8.4from
lazerg:fix/gh-23756-pdo-closecursor-during-step
Open

lazerg wants to merge 1 commit into
php:PHP-8.4from
lazerg:fix/gh-23756-pdo-closecursor-during-step

Conversation

@lazerg

@lazerg lazerg commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

PDOStatement::closeCursor() calls sqlite3_reset() on the underlying sqlite3_stmt. When a collation callback calls it, the reset lands on the statement sqlite3_step() is still running, SQLite tears down the VDBE under itself, and the process segfaults. Re-entering execute() or fetch() from the same callback crashes the same way, through the reset in the parameter hook and the nested step.

The driver statement now records that it is being stepped, and those paths throw an Error instead of reaching SQLite. The running query still finishes, so the statement is usable afterwards. The flag is restored on a bailout too, which keeps closeCursor() working in a shutdown function after a callback called exit().

Fixes #23756

@lazerg
lazerg force-pushed the fix/gh-23756-pdo-closecursor-during-step branch from 3ea4362 to ac4c145 Compare September 19, 2026 01:34
@@ -0,0 +1,24 @@
--TEST--

@devnexen devnexen Sep 19, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: seems this one passes without the fix, the PR description might need some rephrasing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants