Commit e5934f427cc for php
commit e5934f427cc5015f297bb83c92b023d17cff495e
Author: Ilia Alshanetsky <ilia@ilia.ws>
Date: Wed Jun 17 15:21:01 2026 -0400
Fix GH-22051: report errors from SQLite3Result reset and finalize
SQLite3Stmt::reset() reports a failed sqlite3_reset() through
php_sqlite3_error(), but SQLite3Result::reset() returned false silently
and SQLite3Result::finalize() ignored the result. Both now surface the
underlying SQLite error the same way; finalize() keeps its : true return
type and reports without altering the return value.
Fixes GH-22051
Closes GH-22363
diff --git a/NEWS b/NEWS
index 839dfa42e9f..e1bf6e4a3dd 100644
--- a/NEWS
+++ b/NEWS
@@ -77,6 +77,8 @@ PHP NEWS
- SQLite:
. Fixed a crash when SQLite3::close() is called from a userland callback.
(Ilia Alshanetsky)
+ . Fixed bug GH-22051 (Inconsistent error reporting in SQLite3Result::reset()
+ and SQLite3Result::finalize()). (Ilia Alshanetsky)
- Standard:
. Fixed bug #60110 (fclose(), file_put_contents(), copy() do not return false
diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c
index 4698fe5cd09..dbff6508367 100644
--- a/ext/sqlite3/sqlite3.c
+++ b/ext/sqlite3/sqlite3.c
@@ -2167,6 +2167,7 @@ PHP_METHOD(SQLite3Result, reset)
sqlite3result_clear_column_names_cache(result_obj);
if (sqlite3_reset(result_obj->stmt_obj->stmt) != SQLITE_OK) {
+ php_sqlite3_error(result_obj->db_obj, sqlite3_errcode(sqlite3_db_handle(result_obj->stmt_obj->stmt)), "Statement reset reported an error: %s", sqlite3_errmsg(sqlite3_db_handle(result_obj->stmt_obj->stmt)));
RETURN_FALSE;
}
@@ -2192,7 +2193,9 @@ PHP_METHOD(SQLite3Result, finalize)
zend_llist_del_element(&(result_obj->db_obj->free_list), result_obj->stmt_obj,
(int (*)(void *, void *)) php_sqlite3_compare_stmt_free);
} else {
- sqlite3_reset(result_obj->stmt_obj->stmt);
+ if (sqlite3_reset(result_obj->stmt_obj->stmt) != SQLITE_OK) {
+ php_sqlite3_error(result_obj->db_obj, sqlite3_errcode(sqlite3_db_handle(result_obj->stmt_obj->stmt)), "Statement reset reported an error: %s", sqlite3_errmsg(sqlite3_db_handle(result_obj->stmt_obj->stmt)));
+ }
}
RETURN_TRUE;
diff --git a/ext/sqlite3/tests/gh22051.phpt b/ext/sqlite3/tests/gh22051.phpt
new file mode 100644
index 00000000000..b181e7e4a5c
--- /dev/null
+++ b/ext/sqlite3/tests/gh22051.phpt
@@ -0,0 +1,43 @@
+--TEST--
+GH-22051 (SQLite3Result::reset()/finalize() report the error on failure)
+--EXTENSIONS--
+sqlite3
+--FILE--
+<?php
+$db = new SQLite3(':memory:');
+
+// A query whose second step overflows leaves the statement in an error state.
+$sql = "SELECT abs(x) FROM (SELECT 1 AS x UNION ALL SELECT -9223372036854775807 - 1)";
+
+echo "--- SQLite3Result::reset() ---\n";
+$result = $db->query($sql);
+var_dump($result->fetchArray(SQLITE3_NUM));
+var_dump(@$result->fetchArray(SQLITE3_NUM));
+var_dump($result->reset());
+
+echo "--- SQLite3Result::finalize() ---\n";
+$stmt = $db->prepare($sql);
+$result = $stmt->execute();
+var_dump($result->fetchArray(SQLITE3_NUM));
+var_dump(@$result->fetchArray(SQLITE3_NUM));
+var_dump($result->finalize());
+?>
+--EXPECTF--
+--- SQLite3Result::reset() ---
+array(1) {
+ [0]=>
+ int(1)
+}
+bool(false)
+
+Warning: SQLite3Result::reset(): Statement reset reported an error: integer overflow in %s on line %d
+bool(false)
+--- SQLite3Result::finalize() ---
+array(1) {
+ [0]=>
+ int(1)
+}
+bool(false)
+
+Warning: SQLite3Result::finalize(): Statement reset reported an error: integer overflow in %s on line %d
+bool(true)