Skip to content

dxf-g: Fix heap-buffer-overflow in polyline face generation - #245

Open
Meghna45-code wants to merge 2 commits into
BRL-CAD:mainfrom
Meghna45-code:fix-dxf-overflow-228
Open

dxf-g: Fix heap-buffer-overflow in polyline face generation#245
Meghna45-code wants to merge 2 commits into
BRL-CAD:mainfrom
Meghna45-code:fix-dxf-overflow-228

Conversation

@Meghna45-code

Copy link
Copy Markdown
Contributor

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.

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.

1 participant