Skip to content
Open
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
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ PHP NEWS
. Fixed a crash when executing a prepared statement again after a failed
execute() with libmysqlclient. (Ilia Alshanetsky)

- PDO_ODBC:
. Fixed bug GH-25390 (fetching a long text / ntext value allocates the
declared column size when the driver returns SQL_NO_TOTAL). (licvido,
chep6915)

- POSIX:
. Fixed bug GH-25530 (posix_get_last_error() returns an error from a
previous request). (Artem Ukrainskiy)
Expand Down
10 changes: 6 additions & 4 deletions ext/pdo_odbc/odbc_stmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -775,13 +775,15 @@ static int odbc_stmt_get_col(pdo_stmt_t *stmt, int colno, zval *result, enum pdo
* changed from 256 byte to LONG_COLUMN_BUFFER_SIZE.
*/
ssize_t to_fetch_len;
if (orig_fetched_len == SQL_NO_TOTAL && C->datalen > (LONG_COLUMN_BUFFER_SIZE - 1)) {
to_fetch_len = C->datalen;
} else if (orig_fetched_len > 0) {
if (orig_fetched_len > 0) {
/* implicitly not SQL_NO_TOTAL, should be OK */
to_fetch_len = orig_fetched_len;
} else {
/* size must be > 0 to actually get data */
/* SQL_NO_TOTAL: the total length is unknown, so read block by
* block. C->datalen is the declared size of the column (e.g. 2 GB
* for text), not the size of the value, so it must not be used as
* the allocation size here (GH-25390). The block size must be > 0
* to actually get data (GH-23443). */
to_fetch_len = (LONG_COLUMN_BUFFER_SIZE - 1);
}
ssize_t to_fetch_byte = to_fetch_len + 1;
Expand Down
33 changes: 33 additions & 0 deletions ext/pdo_odbc/tests/gh25390.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--TEST--
GH-25390 (fetching a long text / ntext value allocates the declared column size when the driver returns SQL_NO_TOTAL)
--EXTENSIONS--
pdo_odbc
--SKIPIF--
<?php
require 'ext/pdo/tests/pdo_test.inc';
PDOTest::skip();
?>
--INI--
memory_limit=256M
--FILE--
<?php
require 'ext/pdo/tests/pdo_test.inc';
$db = PDOTest::test_factory('ext/pdo_odbc/tests/common.phpt');

/*
* text / ntext are declared as 2 GB / 1 GB by SQL Server drivers; the value
* must be read block by block when the driver cannot tell the total length
* (SQL_NO_TOTAL) instead of allocating the declared size.
*/
foreach ([4073, 300000] as $n) {
$row = $db->query("SELECT CAST(REPLICATE(CAST('A' AS varchar(max)), $n) AS text) AS v")->fetch(PDO::FETCH_ASSOC);
var_dump(strlen($row['v']));
$row = $db->query("SELECT CAST(REPLICATE(CAST(N'A' AS nvarchar(max)), $n) AS ntext) AS v")->fetch(PDO::FETCH_ASSOC);
var_dump(strlen($row['v']));
}
?>
--EXPECT--
int(4073)
int(4073)
int(300000)
int(300000)
Loading