#407 bytea columns are mangled when displayed or exported

Types (2)

I'm using a bytea column to store sha-1 hashes in 24 bytes per hash. However, phpPgAdmin mangles these hashes when displaying them on a webpage or exporting them to a file. For example:

$ psql

psql (9.0.3)
Type "help" for help.

ali=> create table bytea_test (filename text, sha1hash bytea);
ali=> insert into bytea_test values
ali-> ( 'phpPgAdmin-5.0.2.tar.gz'
ali(> , decode('908226ba8482a641172383d58823b171c05029a1','hex') );
ali=> select * from bytea_test;
filename | sha1hash
phpPgAdmin-5.0.2.tar.gz | \x908226ba8482a641172383d58823b171c05029a1
(1 row)

However, phpPgAdmin displays sha1hash as


Which leaves \x90 unchanged, but everything else is replaced by the hexadecimal ascii character code of the hex digit. The problem is related to escapeBytea in classes/database/Postgres.php; either it is broken or it is being used inappropriately. My guess is the former. I've confirmed this issue with phpPgAdmin 4.2.3 and phpPgAdmin 5.0.2 on PHP 5.3.3-1ubuntu9.3 and PostgreSQL 9.0.3. It probably affects a much wider range of configurations, however.


  • Robert Treat

    Robert Treat - 2012-11-28
    • priority: 5 --> 9
    • assigned_to: chriskl --> xzilla
  • Robert Treat

    Robert Treat - 2012-11-28

    Hey, I've been working on this a bit the last few days, with plans to fix it in the next major version of PPA. PHP's bytea handling is pretty poor, so this has taken me longer than I had hoped. Your's is a good usecase to work from though, so thanks for the report. If there's any chance you came up with a fix, I'd love to hear about it, otherwise I'll update this ticket once I get things working.

  • Robert Treat

    Robert Treat - 2013-03-15

    Well, this through us for quite a loop, but this has finally been fixed. I have a patch in my tree at https://github.com/xzilla/phppgadmin/commit/1ab13f459a8ac95c8970d1100edca750ca2048ee which keeps the data from being munged, although it displays it as escape data rather than hex (which psql does). It appears that you can modify classes/database/Postgres.php and set it to false to have it print hex values, which also appears to allow for safe updating, if you really need it to appear that way. That isn't currently recommend though. I will leave this ticket open for a few more days, but I expect to push this patch into the main ppa repo in a few days.

  • Robert Treat

    Robert Treat - 2013-03-20

    This issue has been resolved and is currently fixed in GIT. If
    you wish to acquire the fix, please download the updated code from


    Alternatively, you can download a nightly snapshot from:


    Note that you may have to wait up to 24 hours for the latest GIT
    changes to appear in the snapshot.

  • Robert Treat

    Robert Treat - 2013-03-20
    • status: open --> pending-fixed

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks