Fix segfault in software renderer when malloc fails for large meshes#202
Open
zsoerenm wants to merge 1 commit intosciapp:developfrom
Open
Fix segfault in software renderer when malloc fails for large meshes#202zsoerenm wants to merge 1 commit intosciapp:developfrom
zsoerenm wants to merge 1 commit intosciapp:developfrom
Conversation
When rendering very large surface meshes (e.g. 44445x3334 grid), the vertices_fp allocation in draw_mesh_softwarerendered requires ~78 GB of memory. When malloc returns NULL, the assert is compiled out in release builds (NDEBUG), leading to a NULL pointer dereference and segfault. Replace assert-only checks with proper NULL checks that return GR3_ERROR_OUT_OF_MEM, matching the error handling pattern used elsewhere in the codebase (e.g. gr3_createsurfacemesh). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
draw_mesh_softwarerenderedwhenmallocfails for very large surface meshesassert-only checks with properRETURN_ERROR(GR3_ERROR_OUT_OF_MEM), matching the pattern used elsewhere (e.g.gr3_createsurfacemesh)Problem
When rendering very large surface meshes (e.g. a 44,445 × 3,334 grid from a GNSS signal acquisition plot), the
vertices_fpallocation indraw_mesh_softwarerenderedrequires ~78 GB of memory:When
mallocreturnsNULL, theassert(draw->vertices_fp[draw_id])at line 2384 is compiled out in release builds (NDEBUGdefined), so the code proceeds to write through the NULL pointer, causing a segfault:GDB confirms the crash writes to address
0x0:Fix
Replace
assert-only NULL checks with proper error returns usingRETURN_ERROR(GR3_ERROR_OUT_OF_MEM)in two locations ingr3_sr.c:draw->vertices_fpallocation ingr3_draw_softwarerendered(line 2166)draw->vertices_fp[draw_id]allocation indraw_mesh_softwarerendered(line 2383)Test plan
gcc -fsyntax-only)🤖 Generated with Claude Code