Skip to content

dynafu: zero-initialize Voxel::n in TSDFVolumeCPU::reset() - #4179

Open
shimat wants to merge 1 commit into
opencv:5.xfrom
shimat:fix/dynafu-voxel-n-uninitialized
Open

dynafu: zero-initialize Voxel::n in TSDFVolumeCPU::reset()#4179
shimat wants to merge 1 commit into
opencv:5.xfrom
shimat:fix/dynafu-voxel-n-uninitialized

Conversation

@shimat

@shimat shimat commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

TSDFVolumeCPU::reset() zeros Voxel::v and Voxel::weight but leaves Voxel::n uninitialized. IntegrateInvoker::operator() reads this uninitialized n and passes it straight into WarpField::applyWarp() whenever warpfield->getNodeIndex() is null - i.e. on any integrate() call before the warp field has registered its first node. applyWarp() then indexes WarpField::nodes (unchecked) n times, so garbage left over in the freshly-allocated Mat can produce an out-of-bounds/wild pointer access.

This reproduced as an intermittent SIGSEGV inside applyWarp on macOS arm64 CI in a downstream project (OpenCvSharp), confirmed via crash report: EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x0, faulting thread inside cv::dynafu::WarpField::applyWarp called from cv::dynafu::IntegrateInvoker::operator() via parallel_for_ (dispatch_apply).

Fix: zero-initialize Voxel::n alongside v/weight in reset().

Added a regression test in test_dynafu.cpp that exercises the vulnerable code path (a single synthetic depth frame, no OpenGL or external test data required, unlike the module's existing disabled DynamicFusion tests). Since this is an uninitialized-memory bug, the test can't deterministically reproduce the crash on every run, but it does guard the specific "first frame, no warp nodes yet" scenario going forward.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

TSDFVolumeCPU::reset() zeros Voxel::v and Voxel::weight but leaves Voxel::n uninitialized. IntegrateInvoker::operator() reads this uninitialized n and passes it straight into WarpField::applyWarp() whenever warpfield->getNodeIndex() is null, i.e. on any integrate() call before the warp field has registered its first node. applyWarp() then indexes WarpField::nodes (unchecked) n times, so garbage left over in the freshly-allocated Mat can produce an out-of-bounds/wild pointer access.

This reproduced as an intermittent SIGSEGV inside applyWarp on macOS arm64 CI in a downstream project (OpenCvSharp), confirmed via crash report: EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x0, faulting thread inside WarpField::applyWarp called from IntegrateInvoker::operator() via parallel_for_.

Adds a regression test that exercises the vulnerable code path (a single synthetic depth frame, no OpenGL or external test data required) - note that since this is an uninitialized-memory bug, the test cannot deterministically reproduce the crash on every run, but it does guard the specific "first frame, no warp nodes yet" scenario going forward.
@shimat
shimat force-pushed the fix/dynafu-voxel-n-uninitialized branch from 1a83ff4 to dac5989 Compare July 17, 2026 03:10
shimat added a commit to shimat/opencvsharp that referenced this pull request Jul 17, 2026
cv::dynafu::WarpField::applyWarp crashes intermittently (EXC_BAD_ACCESS/SIGSEGV,
confirmed via macOS arm64 CI crash report) because TSDFVolumeCPU::reset() leaves
Voxel::n uninitialized; IntegrateInvoker reads it and passes it straight into
applyWarp() before the warp field has registered any node. The same signature
(a long hang followed by an access violation) also hit Windows x64 CI on this PR,
consistent with the same uninitialized-memory bug being non-deterministic across
platforms. Upstream fix submitted: opencv/opencv_contrib#4179. Re-enable once
that (or an equivalent) fix lands in the submodule pin.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@asmorkalov
asmorkalov requested a review from savuor August 13, 2026 13:44
@asmorkalov

Copy link
Copy Markdown
Contributor

@savuor Should it be promoted to the main repo somehow?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants