Security: Potential division by zero in norm_cam_gradients#2033
Conversation
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>
|
Hi @barttran2k! Thank you for your pull request and welcome to our community. Action RequiredIn 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. ProcessIn 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 If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
Problem
The
norm_cam_gradientskernel divides by*renderer.n_grad_contributions_dusingFRCP(static_cast<float>(...)). If no spheres contributed to the gradient (i.e., the value is 0), this results in a division by zero, producinginforNaNvalues that can propagate and corrupt downstream computations.Severity:
mediumFile:
pytorch3d/csrc/pulsar/include/renderer.norm_cam_gradients.device.hSolution
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