[Bugfix] Potential null pointer dereference in HeightMap layer operations #214
Labels
No labels
Alpha Release Requirement
Bugfix
Demo Target
Documentation
Major Feature
Minor Feature
priority:tier1-active
priority:tier2-foundation
priority:tier3-future
priority:tier4-deferred
Refactoring & Cleanup
system:animation
system:documentation
system:grid
system:input
system:performance
system:procgen
system:python-binding
system:rendering
system:ui-hierarchy
Tiny Feature
workflow:blocked
workflow:needs-benchmark
workflow:needs-documentation
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
john/McRogueFace#214
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
The HeightMap-to-layer application methods (
apply_threshold,apply_gradient,apply_ranges) do not verify that the HeightMap's internal TCOD pointer is non-null before dereferencing it.Location 1: ValidateHeightMapSize (GridLayers.cpp:50-61)
Location 2: Apply loops (GridLayers.cpp, multiple locations)
When Can This Happen?
A
PyHeightMapObjectcan haveheightmap == nullptrif:TCOD_heightmap_new()in initWhile rare in practice, this violates defensive programming principles and could cause hard-to-diagnose segfaults.
Reproduction (Theoretical)
Proposed Fix
Add null check before
ValidateHeightMapSizein each apply method:Affected Methods
TileLayer.apply_threshold()(GridLayers.cpp:1781)TileLayer.apply_ranges()(GridLayers.cpp:1834)ColorLayer.apply_threshold()(GridLayers.cpp:1233)ColorLayer.apply_gradient()(GridLayers.cpp:1292)ColorLayer.apply_ranges()(GridLayers.cpp:1358)Related
Discovered during code review of #200 and #201 implementations.