Segmentation fault when reading "copy from" in a file #219

Closed
psycoteam opened this Issue Jun 6, 2014 · 2 comments

Projects

None yet

2 participants

@psycoteam

Originally submitted by: Martijn Meijers

With this in a file bug.py:

@@@ python
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

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

This works:

@@@ bash
$ cat load.sql | python bug.py

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

@@@ sql
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.

@dvarrazzo
Member

Yup, segfault confirmed: I'll take a look.

@dvarrazzo
Member

Fixed: the segfault was caused by a missing check in a path normally not used, triggered executing a COPY statement via execute().

@gencer gencer pushed a commit to gencer/psycopg2 that referenced this issue Oct 24, 2014
@dvarrazzo dvarrazzo Fixed segfault if COPY statements are executed
Close ticket #219
56adc59
@gencer gencer pushed a commit to gencer/psycopg2 that referenced this issue Aug 22, 2016
@dvarrazzo dvarrazzo Fixed segfault if COPY statements are executed
Close ticket #219
fd0ba0b
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment