Skip to content

pdo_sqlite segmentation fault #23756

Done

Description

@djarfluka

Description

The following code:

<?php
$db = Pdo\Sqlite::connect('sqlite::memory:');
$db->exec("CREATE TABLE t(x TEXT)");
$db->exec("INSERT INTO t VALUES ('b'),('a'),('c'),('d'),('e')");

$stmt = null;
$db->createCollation('evil', function ($a, $b) use (&$stmt) {
    $stmt->closeCursor();        
    return $a <=> $b;
});

$stmt = $db->prepare("SELECT x FROM t ORDER BY x COLLATE evil");
$stmt->execute();            

Resulted in this output:


Deprecated: Method PDO::sqliteCreateCollation() is deprecated since 8.5, use Pdo\Sqlite::createCollation() instead in /audit/repro/battery7/e7_06_collation_closecursor.php on line 8
AddressSanitizer:DEADLYSIGNAL
=================================================================
==7==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x000000000000 bp 0xffffe64c9040 sp 0xffffe64c9020 T0)
==7==Hint: pc points to the zero page.
==7==The signal is caused by a READ memory access.
==7==Hint: address points to the zero page.
    #0 0x0  (<unknown module>)
LLVMSymbolizer: error reading file: No such file or directory
    #1 0xffffade2578c  (linux-vdso.so.1+0x78c)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (<unknown module>) 
==7==ABORTING

gdb backtrace:

#0  0x0000000000000000 in ?? ()
#1  0x... in ?? () from /lib/.../libsqlite3.so.0
#2  0x... in ?? () from /lib/.../libsqlite3.so.0
#3  sqlite3VdbeExec () from libsqlite3.so.0
#4  sqlite3_step () from libsqlite3.so.0
#5  pdo_sqlite_stmt_execute (stmt=...) at ext/pdo_sqlite/sqlite_statement.c:54
#6  zim_PDOStatement_execute (...) at ext/pdo/pdo_stmt.c:456
...

PHP Version

8.6.0-dev

Operating System

Ubuntu 22.04

Activity

  1. added a commit that references this issue on Sep 19, 2026
    ac4c145
  2. iliaal commented on Sep 20, 2026

    @iliaal
    Member

    Fixed by #23762. The collation callback re-enters the statement that sqlite3_step() is driving, and closeCursor() resets the VDBE mid-compare.

    Confirmed live on PHP-8.4 and PHP-8.5, so a stable-branch fix is the right call. #22739 guards the same re-entry PDO-wide rather than per-driver, but it targets master, so it does not help the released branches.

  3. added a commit that references this issue on Nov 27, 2026
    2f83f3a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions