Skip to content

Segmentation Fault when interleaving fetchmany and fetchone calls #427

@ffelixg

Description

@ffelixg

Here is a test that crashes the interpreter on my x86 Linux machine:

def test_cursor_rownumber_fetchmany_fetchone_interleave(cursor):
    cursor.execute("select 1 union select 2")
    ((val,),) = cursor.fetchmany(1)
    assert val == 1
    (val,) = cursor.fetchone()
    assert val == 2

Probably the issue has something to do with the fact that fetchmany is fetching data using bound columns but fetchone wants to use SQLGetData.

From a quick analysis it looks like SQLGetData is returning SQL_ERROR, which makes sense if the columns are bound. Then the error value is propagated back to fetchone, which seems to be missing an error check. Because of that fetchone then returns the tuple, but since the function had an error, the value inside the tuple is still a null pointer, which then causes the crash when destructuring with (val,)

Metadata

Metadata

Assignees

Labels

triage neededFor new issues, not triaged yet.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions