[php-src] Issue #24233: PDO_PGSQL silently truncates bound strings containing NUL bytes

From: Date: Sat, 10 Oct 2026 01:12:17 +0000
Subject: [php-src] Issue #24233: PDO_PGSQL silently truncates bound strings containing NUL bytes
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-252961@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/24233 Author: binaryfire Binding a string containing a NUL byte silently discards that byte and everything after it. The query succeeds without an error, even with PDO::ERRMODE_EXCEPTION enabled. I understand PostgreSQL doesn't support NUL bytes in text values. But I think PDO should report an error instead of silently truncating the value. ### Reproduce Run this against a PostgreSQL database, adjusting the connection details: ```php <?php $pdo = new PDO( 'pgsql:host=127.0.0.1;dbname=testing', 'postgres', 'password', [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION], ); foreach ([false, true] as $emulatePrepares) { $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, $emulatePrepares); $statement = $pdo->prepare('SELECT CAST(? AS text)'); $statement->execute(["hello\0world"]); var_dump($statement->fetchColumn()); } ``` ### Actual result Both executions succeed and return: ```text string(5) "hello" ``` ### Expected result An error indicating that the value contains an unsupported NUL byte. Here's a [failing Hypervel test that reproduces the issue](https://github.com/hypervel/components/blob/9bb35518f012bff4351c81a562b554ab03204593/tests/Integration/Database/Postgres/DatabasePostgresConnectionTest.php#L35) through a query builder insert.

« previous php.bugs (#252961) next »