Skip to content

Make OSM wrapper construction exception-safe - #324

Closed
t-miller wants to merge 1 commit into
osmcode:masterfrom
t-miller:fix-wrapper-construction-exception-safety
Closed

t-miller wants to merge 1 commit into
osmcode:masterfrom
t-miller:fix-wrapper-construction-exception-safety

Conversation

@t-miller

Copy link
Copy Markdown

An exception during Python OSM wrapper construction leaves m_valid true while m_pyobj is still null. The destructor then dereferences that null object while invalidating _pyosmium_data, turning a Python exception into a native crash.

Set m_valid only after construction and assignment succeed. Add a subprocess regression covering Node, Way and Relation constructors interrupted by KeyboardInterrupt, MemoryError and RuntimeError, including cleanup after the exception is caught.

Fixes #323.

Validation on CPython 3.14.8 / macOS ARM64:

  • New regression: all nine cases crash against the released 4.3.1 native wheel; all nine pass against a locally built 4.3.1 sdist with the identical header fix.
  • test_object_construction.py plus this checkout's test_file_processor.py: 24 passed against that patched native build.
  • Separate application matrix: the same fix removes all 20 construction-related native crashes across 29 subprocess cases; ordinary scan and SQLite cache tests pass.

The native validation build is the 4.3.1 release with this header change, rather than a fresh build of all other current-master source. No signal handlers are suppressed or replaced by the fix.

@lonvia

lonvia commented Oct 15, 2026

Copy link
Copy Markdown
Member

Thanks for finding the issue and proposing a fix. The Python code in a string in the test is a bit unusual and hard to read. I played around with the multiprocessing module and came up with a version in #326 that is closer to a simple function call. Closing here in favour of the other.

@lonvia lonvia closed this Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

OSM wrapper construction exceptions can cause a null-object dereference during destruction

2 participants