Skip to content

[BUG] Converting to cv::Mat causes segmentation fault #3868

Closed
@abrock

Description

@abrock

Describe the bug

I'm trying to use OIIO for reading some files OpenCV can't read.
I made a minimal example: https://github.com/abrock/oiio-bugreport
The program is supposed to read an image, convert it to cv::Mat and print its dimensions but instead I get a segfault with this backtrace:

1 __memmove_avx_unaligned_erms memmove-vec-unaligned-erms.S 396 0x7ffff64d43d5
2 OpenImageIO_v2_2::copy_image(int, int, int, int, void const *, long, long, long, long, void *, long, long, long) 0x7ffff7bb0bcd
3 OpenImageIO_v2_2::parallel_convert_image(int, int, int, int, void const *, OpenImageIO_v2_2::TypeDesc, long, long, long, void *, OpenImageIO_v2_2::TypeDesc, long, long, long, int) 0x7ffff7bb35f8
4 OpenImageIO_v2_2::ImageBufAlgo::to_OpenCV(cv::Mat&, OpenImageIO_v2_2::ImageBuf const&, OpenImageIO_v2_2::ROI, int) 0x7ffff7aff1bf
5 main main.cpp 26 0x55555557255d

This is the relevant code snippet without debug output:

ImageBuf in(fn);
bool const read_success = in.read();
cv::Mat result;
ImageBufAlgo::to_OpenCV(result, in);
println("Size: [{}, {}]", result.cols, result.rows);

To Reproduce

git clone https://github.com/abrock/oiio-bugreport
cd oiio-bugreport/
cmake .
make
./bugreport 8bit.tif

-> segmentation fault.

Expected behavior

No segmentation fault

Evidence

https://github.com/abrock/oiio-bugreport

Platform information:

  • OIIO branch/version: OpenImageIO 2.2.10
  • OS: Debian bullseye
  • C++ compiler: gcc version 10.2.1 20210110 (Debian 10.2.1-6)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugCrash or wrong behavior of an existing feature.good first issueGood one-day project for beginners without much knowledge of the code base.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions