#45377 [NEW]: pg_escape_bytea + pg_query_params -> malformed data

From: Date: Fri, 27 Jun 2008 14:50:54 +0000
Subject: #45377 [NEW]: pg_escape_bytea + pg_query_params -> malformed data
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-126072@lists.php.net to get a copy of this message
From: kk219459 at students dot mimuw dot edu dot pl Operating system: OpenBSD PHP version: 5.2.6 PHP Bug Type: PostgreSQL related Bug description: pg_escape_bytea + pg_query_params -> malformed data Description: ------------ OpenBSD 4.1 Apache/1.3.29 php5-core-5.1.6p1 postgresql-client-8.2.4 I want to insert some binary data to a table. $q = "UPDATE tbl SET data = decode($1, 'base64') WHERE id = $2"; $params = array(base64_encode('binary string'), 123); $res = pg_query_params($q, $params); OK $q = "UPDATE tbl SET data = $1::bytea WHERE id = $2"; $params = array('binary string', 123); $res = pg_query_params($q, $params); ERROR: invalid byte sequence for encoding "UTF8": 0x89 HINT: This error can also happen if the byte sequence does not match the encoding expected by the server, which is controlled by "client_encoding". This could possibly work, but does not. Ok, not a problem. (end of introduction) Reproduce code: --------------- # first $q = "UPDATE tbl SET data = decode($1, 'escape') WHERE id = $2"; $params = array(pg_escape_bytea('binary string'), 123); $res = pg_query_params($q, $params); # second $q = "UPDATE tbl SET data = $1::bytea WHERE id = $2"; $params = array(pg_escape_bytea('binary string'), 123); $res = pg_query_params($q, $params); Expected result: ---------------- Be sure to replace 'binary string' with something more challenging! At least one of these should work (insert the data correctly) Actual result: -------------- Both approaches give the same result. The data gets loaded, but incorrectly. select length(data) from tbl; -- too large data contains character sequences like '\000' instead of their values. btw. select content = decode(encode(data, 'escape'), 'escape') from tbl; -- works (sequence of TRUEs) -- Edit bug report at http://bugs.php.net/?id=45377&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=45377&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=45377&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=45377&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=45377&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=45377&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=45377&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=45377&r=needscript Try newer version: http://bugs.php.net/fix.php?id=45377&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=45377&r=support Expected behavior: http://bugs.php.net/fix.php?id=45377&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=45377&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=45377&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=45377&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=45377&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=45377&r=dst IIS Stability: http://bugs.php.net/fix.php?id=45377&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=45377&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=45377&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=45377&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=45377&r=mysqlcfg

« previous php.bugs (#126072) next »