dxf-g: Fix heap-buffer-overflow in polyline face generation - #245
Open
Meghna45-code wants to merge 2 commits into
Open
dxf-g: Fix heap-buffer-overflow in polyline face generation#245Meghna45-code wants to merge 2 commits into
Meghna45-code wants to merge 2 commits into
Conversation
…on, and MSVC THREADLOCAL definition
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.
This Pull Request fixes the heap-buffer-overflow crash described in BRL-CAD #228 .
The Issue:
1.When parsing a DXF file, BRL-CAD reads physical coordinates (corners) and stores them sequentially in a heap-allocated list called polyline_vert_indices.
2.When parsing a face connection instruction (using a vertex flagged with POLY_VERTEX_FACE), the translator reads the corner indices from the DXF file and saves them to the face array.
3.To build the mesh, BRL-CAD connects these corners by looking up the actual coordinates in the list: polyline_vert_indices[face[i] - 1]
The Vulnerability: The translator trusted the DXF file completely and did not check if the index specified (face[i]) was valid. If the DXF file contains an invalid ID (such as 0 which leads to index -1, or a very large index like 99999 when only a few vertices are defined), the program attempted to access memory outside the bounds of the polyline_vert_indices array, causing a heap-buffer-overflow and immediate crash.
I modified the process_entities_polyline_vertex_code function in dxf-g.c to validate the input indices before passing them to
add_triangle:
1.Added bounds checks to ensure every parsed corner index (face[0], face[1], face[2], face[3]) is >= 1 and <= polyline_vert_indices_count.
2. If a face contains an out-of-bounds index, BRL-CAD now logs a warning and safely skips drawing that triangle instead of accessing invalid memory and crashing.