Skip to content

Invalid arguments cause application crash (segfault) instead of raising an exception #6

Description

@4dreadhead

Invalid arguments cause application crash (segfault) instead of raising an exception

Description

When passing incompatible/invalid arguments to certain gem objects backed by the C++ OpenCV API, the entire Ruby process crashes with a segmentation fault instead of raising a proper Ruby exception (e.g. TypeError or ArgumentError).

This makes it impossible to rescue from such errors, and a single accidental misuse of the API brings down the whole application.

Steps to reproduce

require "opencv-ruby"

Cv::ThresholdTypes::THRESH_BINARY | 1  # crash
Cv::Scalar.new + 1                     # crash
Cv::Vec3b.new + 1                      # crash

Expected behavior

An appropriate Ruby exception should be raised (e.g. TypeError: no implicit conversion of Integer into ...), allowing the caller to rescue and handle the error gracefully.

Actual behavior

The Ruby process crashes with a segmentation fault. Segfault log attached.

Environment

  • Gem: opencv-ruby
  • Ruby: 4.0.1 (2026-01-13 revision e04267a14b) +PRISM
  • OS: Ubuntu 23.04 (kernel 6.2.0-39-generic)

Notes

The operations themselves are logically invalid and are not expected to succeed - the issue is solely that the error surfaces as a native crash rather than a rescuable Ruby exception.

Fault info

fault.txt

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions