Bug 122616

Summary: databases/py-pyPgSQL - apply bytea escape bug patch in PostgreSQL 8.3.1
Product: Ports & Packages Reporter: Choe, Cheng-Dae <whitekid>
Component: Individual Port(s)Assignee: Philip M. Gollucci <pgollucci>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Latest   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff none

Description Choe, Cheng-Dae 2008-04-10 07:20:01 UTC
PostgreSQL 8.3.1 has changed it's bytea encoding.

* in PostgreSQL 8.3.1 Release note
Make encode(bytea, 'escape') convert all high-bit-set byte values into \nnn octal escape sequences (Tom)

This is necessary to avoid encoding problems when the database encoding is multi-byte. This change could pose compatibility issues for applications that are expecting specific results from encode. 

but pyPgSQL escape bytea encode as it's own implementments. PostgreSQL says that it may make failure(see PQescapeBytea documentation).

in PQescapeBytea function documentation:
"The only difference from PQescapeByteaConn is that PQescapeBytea does not take a PGconn parameter. Because of this, it cannot adjust its behavior depending on the connection properties (in particular, whether standard-conforming strings are enabled) and therefore it might give the wrong results. Also, it has no way to return an error message on failure."

This pr will fix this problem uses already patch at pyPgSQL but not applied release.

How-To-Repeat: on PostgreSQL 8.3.1 make table like this as UTF8 encoded database

                            Table "public.files"
   Column    |  Type   |                     Modifiers                      
-------------+---------+----------------------------------------------------
 id          | integer | not null default nextval('files_id_seq'::regclass)
 content     | bytea   | 

and run this code as python test.py Test.testBeforePatch will make error

import unittest
from pyPgSQL import PgSQL

class Test(unittest.TestCase):
        def setUp(self):
                self.conn = PgSQL.connect(database='whitekid', user='whitekid')
                self.binary_data = file('/bin/ls').read()

        def tearDown(self):
                self.conn = None

        def testBeforePatch(self):
                bytea = PgSQL.PgBytea(self.binary_data)
                cursor = self.conn.cursor()
                cursor.execute("insert into files (content) values (%s)", bytea)

        def testAfterPatch1(self):
                bytea = PgSQL.PgBytea(self.binary_data, self.conn)
                cursor = self.conn.cursor()
                cursor.execute("insert into files (content) values (%s)", bytea)

        def testAfterPatch2(self):
                bytea = PgSQL.PgBytea(self.binary_data, self.conn)

                cursor = self.conn.cursor()
                cursor.execute("insert into files (content) values (%s)", bytea)

                cursor.execute("select currval('files_id_seq')")
                id = cursor.fetchone()[0]

                cursor.execute('select content from files where id=%s', id)
                content = cursor.fetchone()[0]

                assert content.value == self.binary_data

unittest.main()

after apply patch run 

python test.py Test.testAfterPatch1
python test.py Test.testAfterPatch2

it make no error!
Comment 1 Edwin Groothuis freebsd_committer freebsd_triage 2008-04-10 12:37:48 UTC
Responsible Changed
From-To: freebsd-ports-bugs->python

Over to maintainer (via the GNATS Auto Assign Tool)
Comment 2 Philip M. Gollucci freebsd_committer freebsd_triage 2010-09-10 03:44:51 UTC
Responsible Changed
From-To: freebsd-python->pgollucci

committer timeout (freebsd-python; 883 days)
Comment 3 dfilter service freebsd_committer freebsd_triage 2010-09-10 05:18:11 UTC
pgollucci    2010-09-10 04:18:06 UTC

  FreeBSD ports repository

  Modified files:
    databases/py-pyPgSQL Makefile distinfo 
  Log:
  PostgreSQL 8.3.1 has changed it's bytea encoding.
  
  * in PostgreSQL 8.3.1 Release note
  Make encode(bytea, 'escape') convert all high-bit-set byte values into \nnn octal escape sequences (Tom)
  
  This is necessary to avoid encoding problems when the database encoding is multi-byte. This change could pose compatibility issues for applications that are expecting specific results from encode.
  
  but pyPgSQL escape bytea encode as it's own implementments. PostgreSQL says that it may make failure(see PQescapeBytea documentation).
  
  in PQescapeBytea function documentation:
  "The only difference from PQescapeByteaConn is that PQescapeBytea does not take a PGconn parameter. Because of this, it cannot adjust its behavior depending on the connection properties (in particular, whether standard-conforming strings are enabled) and therefore it might give the wrong results. Also, it has no way to return an error message on failure."
  
  Patch is included upstream already
  
  PR:             ports/122616
  Submitted by:   "Choe, Cheng-Dae" <whitekid@gmail.com>
  
  Revision  Changes    Path
  1.20      +11 -1     ports/databases/py-pyPgSQL/Makefile
  1.10      +3 -0      ports/databases/py-pyPgSQL/distinfo
_______________________________________________
cvs-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/cvs-all
To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
Comment 4 Philip M. Gollucci freebsd_committer freebsd_triage 2010-09-10 05:18:21 UTC
State Changed
From-To: open->closed

Committed, Thanks!