Repository navigation
Fix segfault when computing filter_geom() cubes - #1
Merged
NewGraphEnvironment merged 2 commits intoSep 1, 2026
Merged
Conversation
filter_geom_cube::read_chunk() assigned a stack-allocated
OGRSpatialReference to the chunk polygon via assignSpatialReference(),
which takes refcounted ownership: ~OGRGeometry() calls Release() on the
SRS, and under GDAL 3 (pimpl'd OGRSpatialReference) the stack object is
destroyed before the polygon at every scope exit, so the release writes
through a dangling pointer. Every computed filter_geom() cube crashed
the worker process with SIGSEGV ("invalid permissions", fault address =
offsetof of the refcount inside GDAL's private SRS struct: 0x120 on GDAL
3.8.5, 0x138 on 3.13.3). Drop the assignment: Contains()/Intersects()
do not use the SRS, and both geometries are already in the cube CRS.
Also close out the log-and-continue error paths in the same code:
- GetDriverByName("GPKG") null check before Create() (constructor)
- GetNextFeature() null check before dereferencing the feature
- GDALRasterize() failure now throws instead of falling through to a
null GetRasterBand() dereference
- RasterIO() failure now throws instead of reading an uninitialized
mask buffer
Fixes appelmar#110
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ENJ9rVrvd9BrixVKtgWtPu
Covers the segfault fixed in the previous commit (appelmar#110): computes a filter_geom() cube from a dummy cube via as_array(), asserting the exact burned-cell count, inside/outside values, and that the mask is identical under 50x50 chunking (exercising the chunk-within-polygon copy fast path). filter_geom() previously had no tests. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ENJ9rVrvd9BrixVKtgWtPu
NewGraphEnvironment
deleted the
110-segfault-in-filter-geom-on-compute
branch
September 1, 2026 03:45
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.
Summary
filter_geom()cube (upstream Segfault in filter_geom() on compute (0.7.4, macOS arm64) appelmar/gdalcubes#110):read_chunk()handed a stack-allocatedOGRSpatialReferencetoOGRPolygon::assignSpatialReference(), which takes refcounted ownership andRelease()s it in~OGRGeometry()— a use-after-destruction under GDAL 3's pimpl'd SRS. The SRS assignment is dropped;Contains()/Intersects()never use it and both geometries are already in the cube CRS.filter_geom.cppwith proper throws:GetDriverByName("GPKG"),GetNextFeature(),GDALRasterize()(was a latent second null-deref segfault), andRasterIO()(was silently reading an uninitialized mask buffer).inst/tinytest/test_filter_geom.R—filter_geom()previously had zero test coverage — asserting exact burned-cell count, inside/outside values, and chunk-layout invariance (exercises the chunk-within-polygon copy fast path).Related Issues
filter_geomon Windows appelmar/gdalcubes#82 (filter_geomempty results on Windows — same worker-process code path)Root cause evidence
offsetof(OGRSpatialReference::Private, nRefCount), which shifts with GDAL's private struct layout. TheassignSpatialReferencecall was the only one in the codebase, which is why onlyfilter_geom()crashed.Test plan
Notes
newgraph(org base branch), so the diff contains only the fix, NEWS entry, and test — suitable for porting upstream as-is.masterwas fast-forwarded to upstream v0.7.4 RC (2cc0d46) first; the 0.7.2 source no longer compiled against GDAL 3.13 and the issue is filed against 0.7.4.🤖 Generated with Claude Code
https://claude.ai/code/session_01ENJ9rVrvd9BrixVKtgWtPu