Skip to content

Invalid input to gtsam.Rot3 causes segfault in python wrapper. #2300

@Robert-Jia00129

Description

@Robert-Jia00129

Description

Constructing a gtsam.Rot3 object from an invalid (non-orthonormal) 3×3 numpy matrix causes a hard crash of the Python interpreter (kernel dies with no traceback), instead of raising a Python exception or a GTSAM error.

This is very very hard to debug in jupyternotebook as it does not show line of error, or exactly what cause the error at all. All it shows is:

The Kernel crashed while executing code in the current cell or a previous cell. 
Please review the code in the cell(s) to identify a possible cause of the failure. 
Click [here](https://aka.ms/vscodeJupyterKernelCrash) for more info. 
View Jupyter [log](command:jupyter.viewOutput) for further details.

Screenshot:
Image

Steps to reproduce

import numpy as np
import gtsam

# This matrix is 3x3 but NOT a valid rotation matrix (not orthonormal, det != 1)
R_invalid = np.array([
    [0.57367956, 0.4419256,  0.87448758],
    [0.94397185, 0.06276365, 0.60304828],
    [0.92277076, 0.43834417, 0.20227668],
])

# This line immediately causes a segfault / kernel crash:
gtsam.Rot3(R_invalid)

Observed behavior:
• Python interpreter terminates instantly (segfault / abort)
• Jupyter kernel dies with message:
“The kernel crashed while executing code…”
• No Python exception is raised.
• No stack trace is printed.

This occurs even if this is the only line executed in a clean environment.

Expected behavior

Rot3 should:
• Validate the input matrix (orthonormality, determinant +1), AND
• Raise a Python exception (e.g., RuntimeError or ValueError) instead of terminating the interpreter.

For example:

raise ValueError("Input matrix is not a valid rotation matrix")

Failing fast with an exception is vastly preferable to a process-level abort.

Environment
• OS: macOS 15 (Apple Silicon)
• Python: 3.9.6 (system Python), also reproducible in Python 3.11 virtual environment
• GTSAM: Wheel distributed for Python (via pip)
• Interface: Python
• Reproduction environments:
• Jupyter Notebook (VS Code)
• Plain Python REPL (python -X faulthandler)
• Minimal scripts run from terminal

The crash occurs regardless of environment.

Additional information

This issue came up during a class assignment where students construct Rot3 from numpy matrices. A single invalid 3×3 matrix instantly kills the kernel, making it difficult for students to debug their code.

A safer behavior (throwing an exception) would be extremely helpful for both users and educators relying on GTSAM in Python-heavy workflows.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions