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 @@ -200,6 +200,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)
Comment thread
chep6915 marked this conversation as resolved.
Resolved

- PDO_PGSQL:
. Fixed bug GH-25838 (use-after-free when a lazy statement follows a failed
query). (Yun Dou)
Expand Down
4 changes: 1 addition & 3 deletions ext/pdo_odbc/odbc_stmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -778,9 +778,7 @@ 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 {
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)