1
0
mirror of https://github.com/php/php-src.git synced 2026-04-29 19:23:22 +02:00

Fix GH-18148: pg_copy_from() wrong \n offset check.

Close GH-18149
This commit is contained in:
David Carlier
2025-03-26 12:47:57 +00:00
parent e28f78ac55
commit 9c6fe6b0ff
3 changed files with 32 additions and 2 deletions
+4
View File
@@ -75,6 +75,10 @@ PHP NEWS
- PDO:
. Fix memory leak when destroying PDORow. (nielsdos)
- PGSQL:
. Fixed bug GH-18148 (pg_copy_from() regression with explicit \n terminator
due to wrong offset check). (David Carlier)
- Standard:
. Fix memory leaks in array_any() / array_all(). (nielsdos)
+4 -2
View File
@@ -3451,11 +3451,13 @@ PHP_FUNCTION(pg_copy_from)
if (UNEXPECTED(!tmp)) {
return;
}
zend_string *zquery = zend_string_alloc(ZSTR_LEN(tmp) + 1, false);
// we give allocation room for a potential command line `\n` terminator addition
zend_string *zquery = zend_string_alloc(ZSTR_LEN(tmp) + 2, false);
memcpy(ZSTR_VAL(zquery), ZSTR_VAL(tmp), ZSTR_LEN(tmp) + 1);
ZSTR_LEN(zquery) = ZSTR_LEN(tmp);
if (ZSTR_LEN(tmp) > 0 && ZSTR_VAL(zquery)[ZSTR_LEN(tmp)] != '\n') {
if (ZSTR_LEN(tmp) > 0 && ZSTR_VAL(zquery)[ZSTR_LEN(tmp) - 1] != '\n') {
ZSTR_VAL(zquery)[ZSTR_LEN(tmp)] = '\n';
ZSTR_VAL(zquery)[ZSTR_LEN(tmp) + 1] = '\0';
ZSTR_LEN(zquery) ++;
}
if (PQputCopyData(pgsql, ZSTR_VAL(zquery), ZSTR_LEN(zquery)) != 1) {
+24
View File
@@ -0,0 +1,24 @@
--TEST--
Fix GH-18148 pg_copy_from() command position offset when giving explicit \n terminator
--EXTENSIONS--
pgsql
--SKIPIF--
<?php
include("inc/skipif.inc");
?>
--FILE--
<?php
include "inc/config.inc";
$table_name = "gh18148";
$db = pg_connect($conn_str);
pg_query($db, "CREATE TABLE {$table_name} (a integer, b text)");
var_dump(pg_copy_from( $db, $table_name, [ "1\tone\n" ] ));
--CLEAN--
<?php
include('inc/config.inc');
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS gh18148 cascade");
?>
--EXPECT--
bool(true)