fix(python/adbc_driver_manager): prevent segfault in _reader.pyx when pyarrow rejects stream schema#4367
Open
rishav394 wants to merge 2 commits into
Open
Conversation
…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.
lidavidm
requested changes
Jun 10, 2026
lidavidm
left a comment
Member
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #4363
Fix
Null-check
c_stream.releasein_AdbcErrorHelper.check_erroritself. If the stream was already released by PyArrow, re-raise the original exception directly instead of callingPyAdbcErrorFromArrayStreamon dangling memory. This protects all callers, not just_import_from_c.Test
Added
test_check_error_with_released_stream- directly tests_AdbcErrorHelperwith a zeroed stream (release == NULL), verifies it re-raises instead of segfaulting.