Commit c400f72
authored
### Rationale for this change
Calling resize on a memory-mapped file that has never been opened 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.
### Are these changes tested?
The regression runs in-process and checks ValueError and its message with pytest.raises. It does not spawn a subprocess.
Separate, 20-second-bounded processes reproduced the original crash and the exception after the fix. Both used native Arrow 26.0.0-SNAPSHOT; the reused patched extension has byte-identical resize source to this PR.
<details>
<summary>Raw logs</summary>
```console
$ python -c 'import pyarrow as pa; pa.MemoryMappedFile().resize(0)'
Before:
returncode=-11
After:
ValueError: I/O operation on closed file
returncode=1
$ cd python
$ python -m pytest pyarrow/tests/test_io.py -k memory_map_resize -q
.. [100%]
2 passed, 161 deselected, 1 warning in 1.02s
```
</details>
### 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.
* GitHub Issue: #51229
Lead-authored-by: 1fanwang <1fannnw@gmail.com>
Co-authored-by: Stefan Wang <1fannnw@gmail.com>
Signed-off-by: AlenkaF <frim.alenka@gmail.com>
1 parent 70f5c26 commit c400f72
2 files changed
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1103 | 1103 | | |
1104 | 1104 | | |
1105 | 1105 | | |
| 1106 | + | |
1106 | 1107 | | |
1107 | 1108 | | |
1108 | 1109 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1223 | 1223 | | |
1224 | 1224 | | |
1225 | 1225 | | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
1226 | 1231 | | |
1227 | 1232 | | |
1228 | 1233 | | |
| |||
0 commit comments