[php-src] master: Merge branch 'PHP-8.5'
| From: | Ilia Alshanetsky | Date: | Sun, 13 Sep 2026 14:28:33 +0000 |
| Subject: | [php-src] master: Merge branch 'PHP-8.5' | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-141184@lists.php.net to get a copy of this message | ||
Author: Ilia Alshanetsky (iliaal)
Date: 2026-09-13T10:21:38-04:00
Commit: https://github.com/php/php-src/commit/0744a9072aa6231226e928fea9cb1ba08135cafd
Raw diff: https://github.com/php/php-src/commit/0744a9072aa6231226e928fea9cb1ba08135cafd.diff
Merge branch 'PHP-8.5'
* PHP-8.5:
ext/pgsql: Restore binary-safe pg_lo_write()
Changed paths:
A ext/pgsql/tests/pg_lo_write_null_bytes.phpt
M NEWS
M ext/pgsql/pgsql.c
M ext/pgsql/tests/05large_object.phpt
Diff:
diff --git a/NEWS b/NEWS
index 8969824fe760..c7f2bb053952 100644
--- a/NEWS
+++ b/NEWS
@@ -20,6 +20,9 @@ PHP NEWS
. Fixed bug GH-23106 (mb_strpos() reads past the end of a haystack ending in
a truncated UTF-8 sequence). (Lazizbek Ergashev)
+- PGSQL:
+ . Fixed pg_lo_write() rejecting data containing null bytes. (Ilia Alshanetsky)
+
- SPL:
. Fixed bug GH-23385 (SplDoublyLinkedList::serialize() use-after-free when
__serialize() removes an element). (David Carlier)
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c
index 351e1b5e3aa3..de50c6929c5c 100644
--- a/ext/pgsql/pgsql.c
+++ b/ext/pgsql/pgsql.c
@@ -2830,7 +2830,7 @@ PHP_FUNCTION(pg_lo_write)
ZEND_PARSE_PARAMETERS_START(2, 3)
Z_PARAM_OBJECT_OF_CLASS(pgsql_id, pgsql_lob_ce)
- Z_PARAM_PATH_STR(str)
+ Z_PARAM_STR(str)
Z_PARAM_OPTIONAL
Z_PARAM_LONG_OR_NULL(z_len, z_len_is_null)
ZEND_PARSE_PARAMETERS_END();
diff --git a/ext/pgsql/tests/05large_object.phpt b/ext/pgsql/tests/05large_object.phpt
index 957f2dffa8ea..a785b76a572d 100644
--- a/ext/pgsql/tests/05large_object.phpt
+++ b/ext/pgsql/tests/05large_object.phpt
@@ -17,11 +17,6 @@ $oid = pg_lo_create ($db);
if (!$oid) echo ("pg_lo_create() error\n");
$handle = pg_lo_open ($db, $oid, "w");
if (!$handle) echo ("pg_lo_open() error\n");
-try {
- pg_lo_write ($handle, "large\0object data");
-} catch (\ValueError $e) {
- echo $e->getMessage(), PHP_EOL;
-}
pg_lo_write ($handle, "large object data");
pg_lo_close ($handle);
pg_exec ($db, "COMMIT");
@@ -110,7 +105,6 @@ echo "OK";
?>
--EXPECTF--
create/write/close LO
-pg_lo_write(): Argument #2 ($data) must not contain any null bytes
open/read/tell/seek/close LO
string(5) "large"
int(5)
diff --git a/ext/pgsql/tests/pg_lo_write_null_bytes.phpt
b/ext/pgsql/tests/pg_lo_write_null_bytes.phpt
new file mode 100644
index 000000000000..44073692a182
--- /dev/null
+++ b/ext/pgsql/tests/pg_lo_write_null_bytes.phpt
@@ -0,0 +1,49 @@
+--TEST--
+pg_lo_write() must accept data containing null bytes
+--EXTENSIONS--
+pgsql
+--SKIPIF--
+<?php include("inc/skipif.inc"); ?>
+--FILE--
+<?php
+include('inc/config.inc');
+
+$db = pg_connect($conn_str);
+pg_exec($db, "BEGIN");
+$oid = pg_lo_create($db);
+$handle = pg_lo_open($db, $oid, "w");
+var_dump(pg_lo_write($handle, "bin\0ary\0data"));
+var_dump(pg_lo_write($handle, "ab\0cd", 4));
+var_dump(pg_lo_write($handle, "ab\0cd", 2));
+var_dump(pg_lo_write($handle, "", 0));
+try {
+ pg_lo_write($handle, "abc", -1);
+} catch (Throwable $e) {
+ echo $e::class, ": ", $e->getMessage(), "\n";
+}
+try {
+ pg_lo_write($handle, "abc", 4);
+} catch (Throwable $e) {
+ echo $e::class, ": ", $e->getMessage(), "\n";
+}
+pg_lo_close($handle);
+pg_exec($db, "ROLLBACK");
+
+pg_exec($db, "BEGIN");
+$oid = pg_lo_create($db);
+$handle = pg_lo_open($db, $oid, "w");
+pg_lo_write($handle, "x\0y");
+pg_lo_close($handle);
+$handle = pg_lo_open($db, $oid, "r");
+var_dump(bin2hex(pg_lo_read($handle)));
+pg_lo_close($handle);
+pg_exec($db, "ROLLBACK");
+?>
+--EXPECT--
+int(12)
+int(4)
+int(2)
+int(0)
+ValueError: pg_lo_write(): Argument #3 ($length) must be greater than or equal to 0
+ValueError: pg_lo_write(): Argument #3 ($length) must be less than or equal to the length of
argument #2 ($buf)
+string(6) "780079"