Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#218 Binary data escaping fails

3.3.3
open
Jakub Vrána
PostgreSQL (25)
5
2015-03-03
2012-01-13
StanleyK
No

When inserting data into a bytea column from a binary file (e.g. a PNG image - using the "Insert" form, that creates a file input for such column), I get the following error:

ERROR: invalid byte sequence for encoding "UTF8": 0x89

Discussion

  • Cruxic
    Cruxic
    2015-03-03

    I get this error too using latest code from github (2015-03-03).

    Here's a work around:

    In the process_input() function (in functions.inc.php) you'll see where it handles bytea and other binary types. Instead of

    return q($file);
    

    do

    $file = base64_encode($file);
    return "decode('$file', 'base64')";
    

    This is postgresql specific of course. It wouldn't be too hard to make this work around proper by making q() take an optional "is_binary" parameter. Each driver could handle binary quoting in it's own way.

    Adminer is a great tool but, in my opinion, it handles binary data poorly. Binary data should be handled with prepared statements, not quoted like a string. The PHP docs on PDO::quote() say as much.