[php-src] master: Merge branch 'PHP-8.4' into PHP-8.5
ndossche <[email protected]> Mon, 3 Aug 2026 20:56:04 +0000
| Newsgroups | gmane.comp.php.cvs.general |
|---|---|
| Message-ID | <[email protected]> |
Author: ndossche (ndossche)
Date: 2026-08-03T22:55:51+02:00
Commit: https://github.com/php/php-src/commit/d2f92b3139631f985713d77e1fd361938ac5684e
Raw diff: https://github.com/php/php-src/commit/d2f92b3139631f985713d77e1fd361938ac5684e.diff
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
sqlite3: Fix leak when trying to close db if blob stream is still open
Changed paths:
A ext/sqlite3/tests/sqlite3_close_blob_stream.phpt
M NEWS
M ext/sqlite3/sqlite3.c
Diff:
diff --git a/NEWS b/NEWS
index 20286543c033..f1b69e3e8ca6 100644
--- a/NEWS
+++ b/NEWS
@@ -43,6 +43,9 @@ PHP NEWS
SO_LINGER options. (Weilin Du)
. Fixed various memory related issues in ext/sockets. (David Carlier)
+- SQLite:
+ . Fix leak when trying to close db if blob stream is still open. (ndossche)
+
- Streams:
. Fixed bug GH-15836 (Use-after-free when a user stream filter accesses
$this->stream during the close flush). (iliaal)
diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c
index a9e2a3a6c305..c9a30cb52e0b 100644
--- a/ext/sqlite3/sqlite3.c
+++ b/ext/sqlite3/sqlite3.c
@@ -2338,7 +2338,9 @@ static void php_sqlite3_object_free_storage(zend_object *object) /* {{{ */
}
if (intern->initialised && intern->db) {
- sqlite3_close(intern->db);
+ /* Use sqlite3_close_v2() because the object may be destroyed while resources depending on the connection are still alive,
+ * e.g. a blob stream created by SQLite3::openBlob(). */
+ sqlite3_close_v2(intern->db);
intern->initialised = false;
}
diff --git a/ext/sqlite3/tests/sqlite3_close_blob_stream.phpt b/ext/sqlite3/tests/sqlite3_close_blob_stream.phpt
new file mode 100644
index 000000000000..d2426445a7cd
--- /dev/null
+++ b/ext/sqlite3/tests/sqlite3_close_blob_stream.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Destroying the SQLite3 object while a blob stream is still open must not leak the connection
+--EXTENSIONS--
+sqlite3
+--FILE--
+<?php
+
+$db = new SQLite3(':memory:');
+$db->exec('CREATE TABLE test (data BLOB)');
+$db->exec("INSERT INTO test (data) VALUES (x'34323432')");
+
+$stream = $db->openBlob('test', 'data', 1);
+var_dump($db->close());
+unset($db);
+var_dump(fread($stream, 4));
+fclose($stream);
+
+?>
+--EXPECTF--
+Warning: SQLite3::close(): Unable to close database: %s in %s on line %d
+bool(false)
+string(4) "4242"