Skip to content

Security: Unsafe reinterpret_cast for Camera Gradient Data#2030

Open
barttran2k wants to merge 1 commit into
facebookresearch:mainfrom
barttran2k:contribai/fix/security/unsafe-reinterpret-cast-for-camera-gradi
Open

Security: Unsafe reinterpret_cast for Camera Gradient Data#2030
barttran2k wants to merge 1 commit into
facebookresearch:mainfrom
barttran2k:contribai/fix/security/unsafe-reinterpret-cast-for-camera-gradi

Conversation

@barttran2k
Copy link
Copy Markdown

Problem

In renderer.norm_cam_gradients.device.h, reinterpret_cast<CamGradInfo*>(renderer.grad_cam_d) is used to reinterpret a float* as a CamGradInfo*. If the underlying memory is not properly aligned or sized for CamGradInfo, this results in undefined behavior, potentially leading to memory corruption or incorrect gradient computation.

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

Solution

Ensure that renderer.grad_cam_d is allocated with proper size and alignment for CamGradInfo. Consider using a typed member instead of reinterpret_cast, or add static_assert checks for size/alignment compatibility.

Changes

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

Testing

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

In `renderer.norm_cam_gradients.device.h`, `reinterpret_cast<CamGradInfo*>(renderer.grad_cam_d)` is used to reinterpret a `float*` as a `CamGradInfo*`. If the underlying memory is not properly aligned or sized for `CamGradInfo`, this results in undefined behavior, potentially leading to memory corruption or incorrect gradient computation.

Affected files: renderer.norm_cam_gradients.device.h

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

meta-cla Bot commented Apr 6, 2026

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