We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e28f78a commit 9c6fe6bCopy full SHA for 9c6fe6b
NEWS
@@ -75,6 +75,10 @@ PHP NEWS
75
- PDO:
76
. Fix memory leak when destroying PDORow. (nielsdos)
77
78
+- PGSQL:
79
+ . Fixed bug GH-18148 (pg_copy_from() regression with explicit \n terminator
80
+ due to wrong offset check). (David Carlier)
81
+
82
- Standard:
83
. Fix memory leaks in array_any() / array_all(). (nielsdos)
84
ext/pgsql/pgsql.c
@@ -3451,11 +3451,13 @@ PHP_FUNCTION(pg_copy_from)
3451
if (UNEXPECTED(!tmp)) {
3452
return;
3453
}
3454
- zend_string *zquery = zend_string_alloc(ZSTR_LEN(tmp) + 1, false);
+ // we give allocation room for a potential command line `\n` terminator addition
3455
+ zend_string *zquery = zend_string_alloc(ZSTR_LEN(tmp) + 2, false);
3456
memcpy(ZSTR_VAL(zquery), ZSTR_VAL(tmp), ZSTR_LEN(tmp) + 1);
3457
ZSTR_LEN(zquery) = ZSTR_LEN(tmp);
- if (ZSTR_LEN(tmp) > 0 && ZSTR_VAL(zquery)[ZSTR_LEN(tmp)] != '\n') {
3458
+ if (ZSTR_LEN(tmp) > 0 && ZSTR_VAL(zquery)[ZSTR_LEN(tmp)-1] != '\n') {
3459
ZSTR_VAL(zquery)[ZSTR_LEN(tmp)] = '\n';
3460
+ ZSTR_VAL(zquery)[ZSTR_LEN(tmp) + 1] = '0円';
3461
ZSTR_LEN(zquery) ++;
3462
3463
if (PQputCopyData(pgsql, ZSTR_VAL(zquery), ZSTR_LEN(zquery)) != 1) {
ext/pgsql/tests/gh18148.phpt
@@ -0,0 +1,24 @@
1
+--TEST--
2
+Fix GH-18148 pg_copy_from() command position offset when giving explicit \n terminator
3
+--EXTENSIONS--
4
+pgsql
5
+--SKIPIF--
6
+<?php
7
+include("inc/skipif.inc");
8
+?>
9
+--FILE--
10
11
12
+include "inc/config.inc";
13
+$table_name = "gh18148";
14
+$db = pg_connect($conn_str);
15
+pg_query($db, "CREATE TABLE {$table_name} (a integer, b text)");
16
+var_dump(pg_copy_from( $db, $table_name, [ "1\tone\n" ] ));
17
+--CLEAN--
18
19
+include('inc/config.inc');
20
21
+pg_query($db, "DROP TABLE IF EXISTS gh18148 cascade");
22
23
+--EXPECT--
24
+bool(true)
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments