[php-src] master: Fix GH-22051: report errors from SQLite3Result reset and finalize

From: Date: Wed, 30 Sep 2026 12:48:04 +0000
Subject: [php-src] master: Fix GH-22051: report errors from SQLite3Result reset and finalize
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-141779@lists.php.net to get a copy of this message
Author: Ilia Alshanetsky (iliaal) Date: 2026-09-30T08:46:27-04:00 Commit: https://github.com/php/php-src/commit/e5934f427cc5015f297bb83c92b023d17cff495e Raw diff: https://github.com/php/php-src/commit/e5934f427cc5015f297bb83c92b023d17cff495e.diff 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 Changed paths: A ext/sqlite3/tests/gh22051.phpt M NEWS M ext/sqlite3/sqlite3.c Diff: diff --git a/NEWS b/NEWS index 839dfa42e9ff..e1bf6e4a3dd6 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 4698fe5cd096..dbff6508367c 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 000000000000..b181e7e4a5c0 --- /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)

« previous php.cvs (#141779) next »