Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ PHP NEWS
registrations are freed while still reachable from the cycle collector.
(Ilia Alshanetsky)

- PGSQL:
. Fixed pg_lo_write() rejecting data containing null bytes. (Ilia Alshanetsky)


24 Sep 2026, PHP 8.5.11

Expand Down
2 changes: 1 addition & 1 deletion ext/pgsql/pgsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -2808,7 +2808,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();
Expand Down
6 changes: 0 additions & 6 deletions ext/pgsql/tests/05large_object.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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)
Expand Down
49 changes: 49 additions & 0 deletions ext/pgsql/tests/pg_lo_write_null_bytes.phpt
Original file line number Diff line number Diff line change
@@ -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"