ports/122616: apply bytea escape bug patch in PostgreSQL 8.3.1

Choe, Cheng-Dae whitekid at gmail.com
Thu Apr 10 06:20:02 UTC 2008


>Number:         122616
>Category:       ports
>Synopsis:       apply bytea escape bug patch in PostgreSQL 8.3.1
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Apr 10 06:20:01 UTC 2008
>Closed-Date:
>Last-Modified:
>Originator:     "Choe, Cheng-Dae"
>Release:        FreeBSD 7.0-STABLE i386
>Organization:
>Environment:
System: FreeBSD w.woosum.net 7.0-STABLE FreeBSD 7.0-STABLE #0: Wed Mar 26 10:57:41 KST 2008 root at w.woosum.net:/usr/obj/usr/src/sys
/WOOSUM i386
>Description:
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!
>Fix:
diff -ruN py-pyPgSQL.orig/Makefile py-pyPgSQL/Makefile
--- py-pyPgSQL.orig/Makefile    2007-06-21 06:24:22.000000000 +0900
+++ py-pyPgSQL/Makefile 2008-04-05 16:23:01.000000000 +0900
@@ -7,7 +7,7 @@
 
 PORTNAME=      pyPgSQL
 PORTVERSION=   2.5.1
-PORTREVISION=  2
+PORTREVISION=  3
 CATEGORIES=    databases python
 MASTER_SITES=  ${MASTER_SITE_SOURCEFORGE}
 MASTER_SITE_SUBDIR=    pypgsql
@@ -27,6 +27,16 @@
 
 DATETIME_DEP=  ${PYTHON_SITELIBDIR}/mx/DateTime/__init__.py
 
+OPTIONS=       BYTEA_CONN      "Apply Bytea connection patch" On
+
+# bypass infrastructure bug
+OPTIONSFILE=   ${PORT_DBDIR}/py-${PORTNAME}/options
+
+.if !defined(WITH_BYTEA_CONN)
+PATCH_SITES=   http://sourceforge.net/tracker/download.php?group_id=16528&atid=316528&file_id=273956&aid=1939119/
+PATCHFILES=    pyPgSQL-patch_byteaconn
+.endif
+
 DOCSDIR=       ${PREFIX}/share/doc/py-pyPgSQL
 EXAMPLESDIR=   ${PREFIX}/share/examples/py-pyPgSQL
 
diff -ruN py-pyPgSQL.orig/distinfo py-pyPgSQL/distinfo
--- py-pyPgSQL.orig/distinfo    2006-07-08 14:29:20.000000000 +0900
+++ py-pyPgSQL/distinfo 2008-04-05 16:23:37.000000000 +0900
@@ -1,3 +1,6 @@
 MD5 (pyPgSQL-2.5.1.tar.gz) = 82670f6f1652aa4766fdaec2cb43debd
 SHA256 (pyPgSQL-2.5.1.tar.gz) = 498486f066f11a68f5b02a54ba5a008d01d507038c873bfd901c14d3f5ca18af
 SIZE (pyPgSQL-2.5.1.tar.gz) = 152840
+MD5 (pyPgSQL-patch_byteaconn) = 97744f64d06efcba79aa13f4dee9c076
+SHA256 (pyPgSQL-patch_byteaconn) = 73a324808aef49382e736245023eb8c468e1ca0803052a2a45162465b0ad28d7
+SIZE (pyPgSQL-patch_byteaconn) = 4718

>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the freebsd-ports-bugs mailing list