Skip to content

Python bindings: Fix crashes when using child objects after Dataset close - #15284

Open
alonfaraj wants to merge 4 commits into
OSGeo:masterfrom
alonfaraj:fix/python-bindings-child-refs
Open

alonfaraj wants to merge 4 commits into
OSGeo:masterfrom
alonfaraj:fix/python-bindings-child-refs

Conversation

@alonfaraj

Copy link
Copy Markdown
Contributor

What does this PR do?

This fix apply pythonappend guard to the accessors that missed it, similar to how it was handled in other functions.

Reproduced on 3.13.3 and master.

Fixed

swig/include/python/gdal_python.i - %extend GDALRasterBandShadow:

  • Band.GetSampleOverview() - SIGSEGV
  • Band.GetDefaultRAT() - SIGSEGV
  • Band.GetRasterColorTable() - SIGSEGV / garbage
  • Band.GetColorTable() - alias of the above
  • Band.GetDataset() - reads freed memory, different error on each run

swig/include/python/gdal_python.i - %extend GDALDatasetShadow:

  • Dataset.GetFieldDomain() - SIGSEGV / garbage
  • Dataset.GetStyleTable() - SIGSEGV / garbage

swig/include/python/ogr_python.i - %extend OGRLayerShadow:

  • Layer.GetSpatialFilter() - SIGSEGV
  • Layer.GetStyleTable() - SIGSEGV / garbage

Tests

Added 8 tests in autotest/gcore/basic_test.py, similar to the existing test_*_use_after_dataset_close pattern:

  • test_sample_ovr_band_use_after_dataset_close
  • test_rat_use_after_dataset_close
  • test_color_table_use_after_dataset_close
  • test_field_domain_use_after_dataset_close
  • test_style_table_use_after_dataset_close
  • test_layer_style_table_use_after_dataset_close
  • test_spatial_filter_use_after_dataset_close
  • test_band_dataset_use_after_dataset_close

What are related issues/pull requests?

AI tool usage

  • AI (Y-a-t-il-un-Copilot-dans-l'avion, Chat-j'ai-pété, Jean-Claude Dusse or something similar) supported my development of this PR. See our policy about AI tool use. Use of AI tools must be indicated.

Tasklist

  • Make sure code is correctly formatted (cf pre-commit configuration)
  • Add test case(s)
  • Add documentation
  • Updated Python API documentation (swig/include/python/docs/)
  • Review
  • Adjust for comments
  • All CI builds and checks have passed
  • ADD YOUR TASKS HERE

Environment

Provide environment details, if relevant:

  • OS: Ubuntu 26.04
  • Compiler: gcc (Ubuntu 15.2.0-16ubuntu1) 15.2.0

Comment thread autotest/gcore/basic_test.py Outdated
Comment thread autotest/gcore/basic_test.py Outdated
@alonfaraj
alonfaraj requested a review from dbaston September 22, 2026 15:08

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants