Skip to content

fix(python/adbc_driver_manager): prevent segfault in _reader.pyx when pyarrow rejects stream schema#4367

Open
rishav394 wants to merge 2 commits into
apache:mainfrom
rishav394:fix/reader-segfault-on-rejected-schema
Open

fix(python/adbc_driver_manager): prevent segfault in _reader.pyx when pyarrow rejects stream schema#4367
rishav394 wants to merge 2 commits into
apache:mainfrom
rishav394:fix/reader-segfault-on-rejected-schema

Conversation

@rishav394

@rishav394 rishav394 commented Jun 9, 2026

Copy link
Copy Markdown

Closes #4363

Fix

Null-check c_stream.release in _AdbcErrorHelper.check_error itself. If the stream was already released by PyArrow, re-raise the original exception directly instead of calling PyAdbcErrorFromArrayStream on dangling memory. This protects all callers, not just _import_from_c.

Test

Added test_check_error_with_released_stream - directly tests _AdbcErrorHelper with a zeroed stream (release == NULL), verifies it re-raises instead of segfaulting.

…s stream schema

When pyarrow.RecordBatchReader._import_from_c rejects a stream schema
(e.g. unsupported format string like Decimal32/64 on PyArrow < 15), it
releases the ArrowArrayStream before raising. The subsequent
check_error() call then accesses the freed stream, causing a
use-after-free segfault.

Add a null-check on c_stream.release after _import_from_c fails. If
PyArrow already released the stream, re-raise the original exception
instead of calling check_error on dangling memory.
@rishav394 rishav394 requested a review from lidavidm as a code owner June 9, 2026 18:43

@lidavidm lidavidm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we have check_error check if the c_stream is released, and if so, just reraise the given exception? Then the unit tests can be a bit simpler, and just directly test _AdbcErrorHelper.

@rishav394 rishav394 requested a review from lidavidm June 10, 2026 05:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

use-after-free in _reader.pyx check_error when PyArrow rejects an unsupported format string

2 participants