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
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ PHP NEWS
- PDO_ODBC:
. Fixed bug GH-20726 (Crash with ODBC connection pooling when the DSN
carries no credentials). (iliaal)
. Fixed bug GH-22667 (Heap buffer over-read when a column value exceeds the
driver-reported display size). (iliaal)

- Phar:
. Fixed inconsistent handling of the magic ".phar" directory. Paths such as
Expand Down
9 changes: 8 additions & 1 deletion ext/pdo_odbc/odbc_stmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,14 @@ static int odbc_stmt_get_col(pdo_stmt_t *stmt, int colno, zval *result, enum pdo
return 1;
} else if (C->fetched_len >= 0) {
/* it was stored perfectly */
ZVAL_STRINGL_FAST(result, C->data, C->fetched_len);
SQLLEN data_len = C->fetched_len;
if (!C->is_long) {
SQLLEN max_len = C->is_unicode ? (SQLLEN)C->datalen + 1 : (SQLLEN)C->datalen;
Comment thread
NattyNarwhal marked this conversation as resolved.
if (data_len > max_len) {
data_len = max_len;
}
}
ZVAL_STRINGL_FAST(result, C->data, data_len);
if (C->is_unicode) {
goto unicode_conv;
}
Expand Down
30 changes: 30 additions & 0 deletions ext/pdo_odbc/tests/gh22667.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--TEST--
GH-22667 (Heap buffer over-read when a column value exceeds the bound buffer)
--EXTENSIONS--
pdo_odbc
--SKIPIF--
<?php
try {
$pdo = new PDO("odbc:Driver=SQLite3;Database=:memory:");
} catch (PDOException $e) {
die("skip requires the SQLite3 ODBC driver");
}
?>
--FILE--
<?php
$pdo = new PDO("odbc:Driver=SQLite3;Database=:memory:");

// The SQLite3 driver reports a 255 byte display size for a computed column, so
// the short-bound buffer holds at most 255 bytes while the value is far longer.
// A conforming driver truncates into the buffer but reports the full length; the
// returned string must stay within the buffer, not over-read past it.
$stmt = $pdo->query("SELECT printf('%.*c', 4096, 'A') AS data");
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$s = $row['data'];

echo "clamped to buffer: "; var_dump(strlen($s) < 4096);
echo "only value bytes: "; var_dump(strlen($s) === substr_count($s, 'A'));
?>
--EXPECT--
clamped to buffer: bool(true)
only value bytes: bool(true)
Loading