[php-src] PHP-8.6: ext/pgsql: fix pg_fetch_all_columns() JIT crash on a modified empty result

From: Date: Wed, 25 Nov 2026 21:57:40 +0000
Subject: [php-src] PHP-8.6: ext/pgsql: fix pg_fetch_all_columns() JIT crash on a modified empty result
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-144178@lists.php.net to get a copy of this message
Author: Tomasz Kowalczyk (thunderer) Committer: David Carlier (devnexen) Date: 2026-11-25T21:55:16Z Commit: https://github.com/php/php-src/commit/684612c85b992f13ed04bdaad10970a47dcea3f0 Raw diff: https://github.com/php/php-src/commit/684612c85b992f13ed04bdaad10970a47dcea3f0.diff ext/pgsql: fix pg_fetch_all_columns() JIT crash on a modified empty result Since 8f6bc97a360, pg_fetch_all_columns() returns the shared immutable empty array for a result without rows. The stub still declared @refcount 1, which lets function JIT and tracing JIT modify the result in place and crash. Drop the annotation. Fix GH-25760 Close GH-25761 Changed paths: A ext/pgsql/tests/gh25760.phpt M NEWS M Zend/Optimizer/zend_func_infos.h M ext/pgsql/pgsql.stub.php M ext/pgsql/pgsql_arginfo.h Diff: diff --git a/NEWS b/NEWS index c5602d1cf86b..99cb66865daa 100644 --- a/NEWS +++ b/NEWS @@ -155,6 +155,10 @@ PHP NEWS . Fixed bug GH-25588 (Use-after-free of a string parameter omitted on a later execute() or rebound while fetching). (Ilia Alshanetsky) +- PGSQL: + . Fixed bug GH-25760 (pg_fetch_all_columns() crashes with JIT when the result + for an empty set is modified). (Tomasz Kowalczyk) + - Phar: . Fixed bug GH-25528 (Phar::setSignatureAlgorithm(): OpenSSL signing reads a freed private key). (Artem Ukrainskiy) diff --git a/Zend/Optimizer/zend_func_infos.h b/Zend/Optimizer/zend_func_infos.h index be2a0c3639b6..a02fce257cee 100644 --- a/Zend/Optimizer/zend_func_infos.h +++ b/Zend/Optimizer/zend_func_infos.h @@ -319,7 +319,7 @@ static const func_info_t func_infos[] = { F1("pg_fetch_array", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_STRING|MAY_BE_ARRAY_OF_NULL|MAY_BE_FALSE), F1("pg_fetch_object", MAY_BE_OBJECT|MAY_BE_FALSE), F1("pg_fetch_all", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_ARRAY), - F1("pg_fetch_all_columns", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING|MAY_BE_ARRAY_OF_NULL), + FN("pg_fetch_all_columns", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING|MAY_BE_ARRAY_OF_NULL), F1("pg_last_oid", MAY_BE_STRING|MAY_BE_LONG|MAY_BE_FALSE), F1("pg_lo_create", MAY_BE_STRING|MAY_BE_LONG|MAY_BE_FALSE), F1("pg_lo_open", MAY_BE_OBJECT|MAY_BE_FALSE), diff --git a/ext/pgsql/pgsql.stub.php b/ext/pgsql/pgsql.stub.php index 9bd78eb3ad4f..61d41dcffc23 100644 --- a/ext/pgsql/pgsql.stub.php +++ b/ext/pgsql/pgsql.stub.php @@ -654,7 +654,6 @@ function pg_fetch_all(PgSql\Result $result, int $mode = PGSQL_ASSOC): array {} /** * @return array<int, string|null> - * @refcount 1 */ function pg_fetch_all_columns(PgSql\Result $result, int $field = 0): array {} diff --git a/ext/pgsql/pgsql_arginfo.h b/ext/pgsql/pgsql_arginfo.h index c9b0c85880da..294212cf3550 100644 --- a/ext/pgsql/pgsql_arginfo.h +++ b/ext/pgsql/pgsql_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 368fabe2efd0e7d490ca80ecab0d92c4d5381e5e */ + * Stub hash: 8f175d8ed14f4bc7156fc232e3280ab06fbe276d */ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_pg_connect, 0, 1, PgSql\\Connection, MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, connection_string, IS_STRING, 0) diff --git a/ext/pgsql/tests/gh25760.phpt b/ext/pgsql/tests/gh25760.phpt new file mode 100644 index 000000000000..69148e9a0432 --- /dev/null +++ b/ext/pgsql/tests/gh25760.phpt @@ -0,0 +1,31 @@ +--TEST-- +GH-25760: pg_fetch_all_columns() crashes with JIT when the result for an empty set is modified +--EXTENSIONS-- +pgsql +opcache +--SKIPIF-- +<?php include("inc/skipif.inc"); ?> +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.jit=function +opcache.jit_buffer_size=64M +opcache.file_update_protection=0 +--FILE-- +<?php +include("inc/config.inc"); + +function test(PgSql\Result $result) { + $columns = pg_fetch_all_columns($result); + $columns[] = 1; + return $columns; +} + +$conn = pg_connect($conn_str); +var_dump(test(pg_query($conn, "SELECT 1 WHERE false"))); +?> +--EXPECT-- +array(1) { + [0]=> + int(1) +}

« previous php.cvs (#144178) next »