DBD::Pg 'lo_read' fails on >= 32768 byte large objects - Mailing list pgsql-bugs

From Kevin Houle
Subject DBD::Pg 'lo_read' fails on >= 32768 byte large objects
Date
Msg-id 27950000.1060888287@discus.blue.cert.org
Whole thread Raw
Responses Re: DBD::Pg 'lo_read' fails on >= 32768 byte large objects  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: DBD::Pg 'lo_read' fails on >= 32768 byte large objects  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
Hello,

There appears to be a bug in the code used by DBD::Pg's 'lo_read'
function. I presume the code with the bug is a part of libpq, and
thus the postgresql-libs RPM binary distribution.

The nature of the bug is that an 'lo_read' operation performed
with DBD::Pg caused a segfault with postgresql-libs-7.3.2 and
"hangs" on files >= 32768 bytes with postgresql-libs-7.3.4. The
hang is actually a read() loop on the socket generating EAGAIN
error on each read().

I've attached a short perl script that demonstrates the bug.
The database server does not seem to matter; I get the same results
using 7.2 as I do with 7.3.x servers. I also get the same results
when I vary the perl-DBD-Pg and perl-DBI module versions. The bug
seems to be following libpg.

All of my testing has been on the i686 platform using linux 2.4.20
kernels.

Test case #1:
 - client = postgresql-libs-7.2.3-5 (redhat-7.3)
            perl-DBI-1.21-1 (redhat-7.3)
            perl-DBD-Pg-1.01-8 (redhat-7.3)
            perl-5.6.1
 - server = postgresql-server-7.3.2-3 (redhat-9)
 - transport = tcpip + ssl

 $ perl test.pl
 - reading testfile '/bin/ls'
 - inserting testfile contents
 - oid = '16265435'
 - reading large object
 success.. removing large object

Test case #2:
 - client = postgresql-libs-7.3.2-3 (redhat-9)
            perl-DBI-1.32-5 (redhat-9)
            perl-DBD-Pg-1.21-2 (redhat-9)
 -server = postgresql-server-7.3.2-3 (redhat-9)
 -transport = tcpip + ssl

 $ perl test.pl
 - reading testfile '/bin/ls'
 - inserting testfile contents
 - oid = '16265436'
 - reading large object
 Segmentation fault

 ... after ~32768 bytes, process loops reading the socket
  read(3, 0x81cc938, 5) = -1 EAGAIN (Resource temporarily unavailable)
 and eventually segfaults

Test case #3:
 - same as #2 except
 - transport = tcpip (localhost)

 $ perl test.pl
 - reading testfile '/bin/ls'
 - inserting testfile contents
 - oid = '16265436'
 - reading large object
 Segmentation fault

Test case #4:
 - same as #2 and #3 except
 - postgresql-libs-7.3.4 PGDG used

 $ perl test.pl
 - reading testfile '/bin/ls'
 - inserting testfile contents
 - oid = '16265437'
 - reading large object

 ... after ~32768 bytes, process loops reading the socket
  read(3, 0x81cc938, 5) = -1 EAGAIN (Resource temporarily unavailable)
 but doesn't appear to segfault (unless I am not patient enough)

This problem is a bastard as it makes getting data out of an
otherwise perfectly good database rather difficult. In other
words, its a show-stopper when migrating from 7.2 -> 7.3.

Regards,
Kevin

Attachment

pgsql-bugs by date:

Previous
From: Andreas Hinz
Date:
Subject: ALTER SCHEMA problem
Next
From: "scott.marlowe"
Date:
Subject: two minor issues with date time types