Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Segmentation fault when reading "copy from" in a file

#219

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.

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

State: resolved
Milestone: none
Assigned to: nobody

Activity

  1. Daniele Varrazzo
    Daniele Varrazzo
    • State changed from new to open

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

    June 6th, 2014 @ 02:10 PM

  2. Daniele Varrazzo
    Daniele Varrazzo
    • State changed from open to resolved

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

    June 6th, 2014 @ 07:46 PM