Security: Type punning via IASF macro causes undefined behavior - #2035
Conversation
In `renderer.fill_bg.device.h`, the `IASF` macro is used to store an integer value (`sphere_id = -1`) into a float memory location via type punning. This is undefined behavior in C++ unless performed through `memcpy` or `std::bit_cast`. Compilers may optimize this incorrectly under strict aliasing rules, leading to unpredictable behavior. Affected files: renderer.fill_bg.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
In
renderer.fill_bg.device.h, theIASFmacro is used to store an integer value (sphere_id = -1) into a float memory location via type punning. This is undefined behavior in C++ unless performed throughmemcpyorstd::bit_cast. Compilers may optimize this incorrectly under strict aliasing rules, leading to unpredictable behavior.Severity:
lowFile:
pytorch3d/csrc/pulsar/include/renderer.fill_bg.device.hSolution
Use
memcpyfor type punning instead of the IASF macro to ensure well-defined behavior:memcpy(&renderer.forw_info_d[write_loc + 3 + i * 2], &sphere_id, sizeof(float));Changes
pytorch3d/csrc/pulsar/include/renderer.fill_bg.device.h(modified)Testing