NVIDIA / NVIDIA/warp

compute_average_mesh_edge_length: out-of-bounds read and divide-by-zero for an empty mesh (num_tris == 0)

Open Beginner friendly
#1,602 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
7.1k
Forks
624
Avg merge
3d 17h
Merged PRs (30d)
5

Description

Describe the bug

compute_average_mesh_edge_length in warp/native/mesh.cu unconditionally indexes sum_edge_lengths[n - 1] and divides by 3 * n:

__global__ void compute_average_mesh_edge_length(int n, float* sum_edge_lengths, Mesh* m)
{
    m->average_edge_length = sum_edge_lengths[n - 1] / (3 * n);
}

For an empty mesh (n == 0, i.e. no triangles), this reads sum_edge_lengths[-1] — an out-of-bounds device read (and sum_edge_lengths may itself be a zero-length / null buffer) — and divides by zero, producing a NaN average_edge_length, which is then used as the welding epsilon.

Location

warp/native/mesh.cu, compute_average_mesh_edge_length (≈ lines 57–60).

Reachability

Constructing a wp.Mesh with empty indices on a CUDA device.

Suggested fix

Guard the empty case — either skip the three launches when num_tris == 0 on the host side, or in-kernel:

m->average_edge_length = (n > 0) ? sum_edge_lengths[n - 1] / (3.0f * n) : 0.0f;

This removes the out-of-bounds read and the divide-by-zero, and aligns the CUDA path with the CPU path for a degenerate (empty) mesh.

Note on verification

Found by static analysis; I don't have a Warp build locally, so I have not reproduced the OOB at runtime. A maintainer could confirm by creating a wp.Mesh with empty indices on CUDA under compute-sanitizer --tool memcheck. Filing in case it's useful; happy to open a PR if the suggested fix looks right.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in warp/native/mesh.cu at compute_average_mesh_edge_length and trace the CUDA launches reached when a wp.Mesh has empty indices. Verify the empty case with compute-sanitizer --tool memcheck and confirm that average_edge_length is finite and matches the CPU path without an out-of-bounds read or divide-by-zero.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
backend, testing-qa
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.