Skip to content

aruco: fix SIGSEGV in detectMarkers on ARM/Raspberry Pi (issue #3938)#4102

Open
Utkarshkhandka wants to merge 1 commit intoopencv:4.xfrom
Utkarshkhandka:fix/aruco-segfault-arm
Open

aruco: fix SIGSEGV in detectMarkers on ARM/Raspberry Pi (issue #3938)#4102
Utkarshkhandka wants to merge 1 commit intoopencv:4.xfrom
Utkarshkhandka:fix/aruco-segfault-arm

Conversation

@Utkarshkhandka
Copy link
Copy Markdown

Summary

Fixes SIGSEGV crash in cv2.aruco.detectMarkers() on ARM/aarch64
(Raspberry Pi 5, Bookworm, Python 3.11, OpenCV 4.6.0).

Issue

Closes #3938

Root Cause

makePtr<DetectorParameters>() used as a default argument in aruco.hpp
is evaluated at the call site on ARM. The Ptr<> refcount block is not
fully ready before the function dereferences it, causing SIGSEGV at 0x60.
The same pattern exists across all legacy wrapper functions.

Fix

  • Changed all makePtr<>() default args in headers to safe null Ptr<>()
  • All implementations now create defaults internally when null is passed
  • Added CV_Assert null guards before every Ptr<> dereference
  • Added try/catch around solvePnP calls to prevent unhandled exceptions
  • Fixed wrong include guard in precomp.hpp (ccalib -> aruco)
  • Fixed CV_Assert abort on empty frames in calibrateCameraAruco
  • Added 4 ARM regression tests to test_aruco.py

Tested

  • Raspberry Pi 5, Bookworm, Python 3.11, OpenCV 4.6.0 (ARM/aarch64)
  • Both old API and new API confirmed working after fix
  • All existing tests pass

…#3938)

On ARM/aarch64 (Raspberry Pi 5, Bookworm, OpenCV 4.6.0), calling
detectMarkers() with the new API causes SIGSEGV at address 0x60.

Root cause: makePtr<DetectorParameters>() used as a default argument
in the header is evaluated at the call-site on ARM. The Ptr<> object
is not fully constructed before the function dereferences it.

Changes:
- aruco.hpp: replace makePtr<> default args with Ptr<>() (null),
  handle null safely in impl with internal fallback construction
- aruco.cpp: null guards on all Ptr<> dereferences; try/catch around
  solvePnP calls; safe fallback for null default args
- charuco.cpp: null guards on all Ptr<> dereferences; safe fallback
  for null dictionary default in detectCharucoDiamond
- aruco_calib.cpp: null guards on board; changed CV_Assert on empty
  frames to continue (valid real-world scenario)
- precomp.hpp: fix wrong include guard name (was ccalib, should be aruco)
- test_aruco.py: add ARM regression tests for issue opencv#3938

Fixes: opencv#3938
@Utkarshkhandka
Copy link
Copy Markdown
Author

Hi @opencv-bot, could you please approve the CI workflow run for this PR?
This fixes a confirmed SIGSEGV on Raspberry Pi 5 (ARM/aarch64) documented in issue #3938.
Thank you!

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.

Segmentation Fault in ArUco Detection on Raspberry Pi (ARM) with OpenCV 4.6.0

1 participant