This project is archived and is in readonly mode.

#219 ✓resolved
Martijn Meijers

Segmentation fault when reading "copy from" in a file

Reported by Martijn Meijers | June 6th, 2014 @ 07:40 AM

With this in a file bug.py:

import sys
import psycopg2
DSN = "host={0} dbname={1} user={2} password={3} port={4} sslmode={5}"
dsn = DSN.format("host", "db", "user", "****", 5432, "prefer")
dbconn = psycopg2.connect(dsn)
for line in sys.stdin:
    c = dbconn.cursor()
    c.execute(line)
    c.close()
dbconn.close()
print sys.argv[0], "done"
sys.exit(0)

And this in load.sql

DROP TABLE IF EXISTS foo;
CREATE TABLE foo (id integer);

This works:

$ cat load.sql | python bug.py

However, putting the following in load.sql segfaults the Python interpreter:

DROP TABLE IF EXISTS foo;
CREATE TABLE foo (id integer);
COPY foo FROM STDIN;
1
2
3
4
5
6
\.

Maybe what I am doing in the second case is not allowed (if I perform similar things, but with the copy_from method on the cursor it works ok), but the above should definitely not segfault the Python interpreter.

Tested with Python 2.7.3 and a fresh psycopg2 2.5.3 installation in a virtualenv.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

<b>WARNING:</b> the informations in this tracker are archived. Please submit new tickets or comments to <a href="https://github.com/psycopg/psycopg2/issues">the new tracker</a>.
<br/>
Psycopg is the most used PostgreSQL adapter for the Python programming language. At the core it fully implements the Python DB API 2.0 specifications. Several extensions allow access to many of the features offered by PostgreSQL.

Shared Ticket Bins

Pages