Skip to content

Security: Potential division by zero in norm_cam_gradients#2033

Open
barttran2k wants to merge 1 commit into
facebookresearch:mainfrom
barttran2k:contribai/fix/security/potential-division-by-zero-in-norm-cam-g
Open

Security: Potential division by zero in norm_cam_gradients#2033
barttran2k wants to merge 1 commit into
facebookresearch:mainfrom
barttran2k:contribai/fix/security/potential-division-by-zero-in-norm-cam-g

Conversation

@barttran2k

Copy link
Copy Markdown

Problem

The norm_cam_gradients kernel divides by *renderer.n_grad_contributions_d using FRCP(static_cast<float>(...)). If no spheres contributed to the gradient (i.e., the value is 0), this results in a division by zero, producing inf or NaN values that can propagate and corrupt downstream computations.

Severity: medium
File: pytorch3d/csrc/pulsar/include/renderer.norm_cam_gradients.device.h

Solution

Add a guard before the division: if (*renderer.n_grad_contributions_d > 0) { *cgi = *cgi * FRCP(static_cast<float>(*renderer.n_grad_contributions_d)); }

Changes

  • pytorch3d/csrc/pulsar/include/renderer.norm_cam_gradients.device.h (modified)

Testing

  • Existing tests pass
  • Manual review completed
  • No new warnings/errors introduced

The `norm_cam_gradients` kernel divides by `*renderer.n_grad_contributions_d` using `FRCP(static_cast<float>(...))`. If no spheres contributed to the gradient (i.e., the value is 0), this results in a division by zero, producing `inf` or `NaN` values that can propagate and corrupt downstream computations.

Affected files: renderer.norm_cam_gradients.device.h

Signed-off-by: Trần Bách <45133811+barttran2k@users.noreply.github.com>
@meta-cla

meta-cla Bot commented Apr 6, 2026

Copy link
Copy Markdown

Hi @barttran2k!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

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