Skip to content

Navigation Menu

Sign in
Sign up

GH-51229: [Python] Raise instead of crashing on unopened resize - #51246

Open
1fanwang wants to merge 2 commits into
apache:main from
1fanwang:1fannnw/gh-51229-memory-mapped-file-resize
Open

GH-51229: [Python] Raise instead of crashing on unopened resize #51246
1fanwang wants to merge 2 commits into
apache:main from
1fanwang:1fannnw/gh-51229-memory-mapped-file-resize

Conversation

@1fanwang

@1fanwang 1fanwang commented Sep 8, 2026
edited by github-actions Bot
Loading

Copy link
Copy Markdown
Contributor

Rationale for this change

pa.MemoryMappedFile() can be constructed without opening a file. Calling resize on that object dereferences an empty native handle and takes down the Python process with a SIGSEGV, so an application cannot catch or recover from it.

What changes are included in this PR?

The resize path now applies the same open-state check the other file operations already use, before it reaches the native resize call. A directly constructed object raises ValueError("I/O operation on closed file").

Are these changes tested?

Yes. The regression drives the call in a subprocess so a crash is observable rather than fatal to the test run.

$ git checkout main -- python/pyarrow/io.pxi && python -m pytest \
 python/pyarrow/tests/test_io.py -k memory_map_resize -q
E subprocess.CalledProcessError: Command '[...]' died with <Signals.SIGSEGV: 11>.
1 failed, 162 deselected in 0.73s
$ git checkout HEAD -- python/pyarrow/io.pxi && python -m pytest \
 python/pyarrow/tests/test_io.py -k memory_map_resize -q
2 passed, 161 deselected in 0.23s

Are there any user-facing changes?

Yes. Misuse of a directly constructed memory-mapped file now raises a Python exception instead of terminating the process.

This PR contains a "Critical Fix". It fixes a process crash reachable from ordinary Python-level object state.

Reject resize calls on directly constructed MemoryMappedFile objects before dereferencing the native handle.
Generated-by: GitHub Copilot CLI (Claude Opus 5)
Signed-off-by: Stefan Wang <1fannnw@gmail.com>
Copilot AI lite review requested due to automatic review settings September 8, 2026 19:51

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

⚠️ GitHub issue #51229 has been automatically assigned in GitHub to PR creator.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The change correctly prevents a reproducible segfault by aligning resize() with existing open-state checks, and the regression is covered by a subprocess-based test.

Pull request overview

This PR addresses a Python-level crash in pyarrow.MemoryMappedFile.resize() when MemoryMappedFile() is constructed without opening a file, by adding an open-state guard so the misuse raises a catchable exception instead of segfaulting.

Changes:

  • Add _assert_open() to the MemoryMappedFile.resize() wrapper before calling the native resize implementation.
  • Add a regression test that exercises the behavior in a subprocess so a segfault would be observable without killing the pytest runner.
File summaries
File Description
python/pyarrow/io.pxi Adds an open-state assertion to MemoryMappedFile.resize() to prevent dereferencing a null native handle.
python/pyarrow/tests/test_io.py Adds a subprocess-based regression test ensuring uninitialized MemoryMappedFile().resize() raises ValueError instead of crashing.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread python/pyarrow/io.pxi
@github-actions github-actions Bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Sep 8, 2026
Comment thread python/pyarrow/tests/test_io.py
The subprocess wrapper guarded against the crash this change removes, so
the in-process form reads better now.
Signed-off-by: 1fanwang <1fannnw@gmail.com>
Copilot AI review requested due to automatic review settings September 10, 2026 11:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new regression test currently runs the crashing call in-process, so a future regression could abort the entire pytest process rather than failing cleanly.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment on lines +1219 to +1223
def test_memory_map_resize_uninitialized():
with pytest.raises(ValueError, match="I/O operation on closed file"):
pa.MemoryMappedFile().resize(0)


Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Keeping it in-process per #51246 (comment); with the fix it raises rather than crashing.

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.

Only the PR description needs an update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@AlenkaF AlenkaF AlenkaF left review comments
Copilot code review Copilot
Copilot review effort, defaults to Lite
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@raulcd raulcd Awaiting requested review from raulcd raulcd is a code owner
@rok rok Awaiting requested review from rok rok is a code owner

Assignees

No one assigned

Labels

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /