Skip to content

mesh: validate dimensions, null pointers and indices at the public boundary - #4517

Merged
jhale merged 3 commits into
mainfrom
jhale/mesh-review-wp3-boundary-validation
Sep 18, 2026
Merged

jhale merged 3 commits into
mainfrom
jhale/mesh-review-wp3-boundary-validation

Conversation

@jhale

@jhale jhale commented Sep 15, 2026

Copy link
Copy Markdown
Member

Several public entry points took dimension/index arguments, or
shared_ptr arguments, with no validation at all, so bad
input from Python was undefined behaviour in Release rather than an
exception: Topology::index_map(s) indexed _entity_types with unchecked
operator[] (the root cause several other constructors route through),
cell_types.cpp's entity/sub-entity lookups indexed basix tables directly,
EntityMap's and MeshTags' constructors dereferenced their Topology
arguments before checking them, create_geometry never validated its
gdim argument or cross-checked x/nodes/xdofs sizes, compute_incident_entities
passed caller entity indices straight into an unchecked AdjacencyList
lookup, reorder_cells never validated a user reorder_fn's returned
permutation, and transfer_meshtags_to_submesh never checked that its
EntityMap arguments actually related the topologies it was given -
swapping them (the natural mistake, since that's create_submesh's own
return order) was an unchecked OOB read and write.

Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com


Stack created with GitHub Stacks CLIGive Feedback 💬

@jhale
jhale added this pull request to stack #4520 September 15, 2026 09:18
Comment thread python/test/unit/mesh/test_mesh.py
Comment thread python/test/unit/mesh/test_mesh.py Outdated
@jhale
jhale force-pushed the jhale/mesh-review-wp3-boundary-validation branch from bbdc9f9 to 1b040bd Compare September 15, 2026 13:03
@jhale
jhale marked this pull request as ready for review September 15, 2026 13:05
@jhale
jhale force-pushed the jhale/mesh-review-wp3-boundary-validation branch from 1b040bd to 8187cd3 Compare September 15, 2026 13:12
@jhale
jhale force-pushed the jhale/mesh-review-wp3-boundary-validation branch from 8187cd3 to 3f54bc1 Compare September 15, 2026 13:50
@jhale
jhale force-pushed the jhale/mesh-review-wp3-boundary-validation branch from 3f54bc1 to b27bd63 Compare September 15, 2026 13:59
@jhale
jhale force-pushed the jhale/mesh-review-wp3-boundary-validation branch 2 times, most recently from f7cbb66 to 9bfbd33 Compare September 16, 2026 08:16
Comment thread cpp/dolfinx/mesh/EntityMap.h
Comment thread cpp/dolfinx/mesh/utils.cpp
@jhale
jhale force-pushed the jhale/mesh-review-wp3-boundary-validation branch from 9bfbd33 to 560c48e Compare September 16, 2026 15:19
Comment thread cpp/dolfinx/mesh/utils.h
Comment thread cpp/dolfinx/mesh/utils.h
Base automatically changed from jhale/mesh-review-wp2-assert-to-throw to main September 17, 2026 06:27
@jhale
jhale force-pushed the jhale/mesh-review-wp3-boundary-validation branch 2 times, most recently from 338822f to b3dd996 Compare September 17, 2026 11:18
jhale and others added 3 commits September 17, 2026 18:39
…undary

Several public entry points took dimension/index arguments, or
shared_ptr<const Topology> arguments, with no validation at all, so bad
input from Python was undefined behaviour in Release rather than an
exception: Topology::index_map(s) indexed _entity_types with unchecked
operator[] (the root cause several other constructors route through),
cell_types.cpp's entity/sub-entity lookups indexed basix tables directly,
EntityMap's and MeshTags' constructors dereferenced their Topology
arguments before checking them, create_geometry never validated its
gdim argument or cross-checked x/nodes/xdofs sizes, compute_incident_entities
passed caller entity indices straight into an unchecked AdjacencyList
lookup, reorder_cells never validated a user reorder_fn's returned
permutation, and transfer_meshtags_to_submesh never checked that its
EntityMap arguments actually related the topologies it was given -
swapping them (the natural mistake, since that's create_submesh's own
return order) was an unchecked OOB read and write.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@jhale
jhale force-pushed the jhale/mesh-review-wp3-boundary-validation branch from b3dd996 to 79ee1eb Compare September 17, 2026 16:39
@jhale
jhale dismissed garth-wells’s stale review September 17, 2026 16:41

Braces added - why can't this be linted without heavy tools like clang-tidy...

@jhale
jhale added this pull request to the merge queue Sep 18, 2026
Merged via the queue into main with commit a9bc314 Sep 18, 2026
22 checks passed
@jhale
jhale deleted the jhale/mesh-review-wp3-boundary-validation branch September 18, 2026 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants