Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileStorage SIGSEGV (without doing I/O) #185

Closed
framp opened this issue Dec 6, 2020 · 2 comments
Closed

FileStorage SIGSEGV (without doing I/O) #185

framp opened this issue Dec 6, 2020 · 2 comments

Comments

@framp
Copy link

framp commented Dec 6, 2020

First, thanks a lot for this monumental work, it's great to have opencv in rust land!

  1. Operating system: MacOS
  2. The way you installed OpenCV: nix-darwin opencv4.3, brew opencv 4.5
  3. OpenCV version: 4.3, 4.5
  4. rustc version: 1.48.0

I have a small program which SIGSEGV sporadically; it calls a few opencv functions - these ones in particular (or real code here):

let src = Mat::from_slice(&buffer).unwrap();
let src = src.reshape(4, h as i32).unwrap();
in_range(&src, &Scalar::new(...),  &Scalar::new(...), &mut mask)?;
bitwise_or(&mask, &mask2, &mut mask3, &Mat::default()?)?;
find_contours(&mask3, &mut contours, ...)?;
for contour in contours {
    contour_area(&contour, false)?;
    moments(&contour, true)?
}

If I call this code several times, after a few times it will spawn a lot of threads:

[New Thread 0xf0f of process 45225]
[New Thread 0x150b of process 45225]
[New Thread 0x1707 of process 45225]
[New Thread 0x1807 of process 45225]
[New Thread 0x1907 of process 45225]
[New Thread 0x1a07 of process 45225]
[New Thread 0x1b07 of process 45225]
[New Thread 0x1c07 of process 45225]
[New Thread 0x1d07 of process 45225]
[New Thread 0x1e07 of process 45225]
[New Thread 0x1f07 of process 45225]
[New Thread 0x2007 of process 45225]
[New Thread 0x2107 of process 45225]
[New Thread 0x2207 of process 45225]
[New Thread 0x2307 of process 45225]
[New Thread 0x2407 of process 45225]
[New Thread 0x2507 of process 45225]
[New Thread 0x280b of process 45225]
[New Thread 0x2b0b of process 45225]

and then SIGSEGV.

At no point I ever read or write to file storage. Funnily enough the backtrace of my SIGSEGV points at:
On opencv 4.3

#0  0x00007fff36e8b159 in ?? ()
#1  0x000070000f270230 in ?? ()
#2  0x000070000f270308 in ?? ()
#3  0x000070000f270308 in ?? ()
#4  0x000070000f270290 in ?? ()
#5  0x000070000f270000 in ?? ()
#6  0x34cc42fed19d000b in ?? ()
#7  0x000070000f2706e0 in ?? ()
#8  0x000070000f2705e0 in ?? ()
#9  0x000070000f270280 in ?? ()
#10 0x00000001000a28f9 in opencv::opencv::hub::core::write_str (fs=0x1000a29c0 <opencv::opencv::hub::core::write_str+800>, name=..., value=...)
    at /Users/framp/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.46.3/src/opencv/hub/core.rs:6239
#11 0x000070000f2702a0 in ?? ()
#12 0x0000000103a04a00 in ?? ()
#13 0x00000001038214f0 in ?? ()
#14 0x00000001038214f0 in ?? ()
#15 0x000070000f2702a0 in ?? ()
#16 0x00000001000a1891 in opencv::opencv::hub::core::vconcat2 (src1=..., src2=..., dst=...) at /Users/framp/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.46.3/src/opencv/hub/core.rs:6158
#17 0x00000001038214e0 in ?? ()
#18 0x00000001038214f0 in ?? ()
#19 0x000070000f2702d0 in ?? ()
#20 0x00000001000a19fa in opencv::opencv::hub::core::vconcat2 (src1=..., src2=..., dst=...) at /Users/framp/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.46.3/src/opencv/hub/core.rs:6159
#21 0x000070000f2702d0 in ?? ()
#22 0x00000001038214f0 in ?? ()
#23 0x00000001038214f0 in ?? ()
#24 0x00000001038214f0 in ?? ()
#25 0x000070000f270380 in ?? ()
#26 0x00000001000a4e7f in opencv::opencv::hub::core::FileStorage::new (filename=..., flags=0, encoding=...)
    at /Users/framp/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.46.3/src/opencv/hub/core.rs:7849
#27 0x000000010b350000 in ?? ()
#28 0x00000001038214f0 in ?? ()
#29 0x00000001038214e0 in ?? ()
#30 0x000070000f2703c0 in ?? ()
#31 0x00000000007a8000 in ?? ()
#32 0x0000000000000000 in ?? ()

On opencv 4.5

0x00000001000a122c in opencv::opencv::hub::core::vconcat2 (src1=..., src2=..., dst=...) at /Users/framp/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.46.3/src/opencv/hub/core.rs:6165
6165            input_array_arg!(src1);
(gdb) bt
#0  0x00000001000a122c in opencv::opencv::hub::core::vconcat2 (src1=..., src2=..., dst=...) at /Users/framp/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.46.3/src/opencv/hub/core.rs:6165
#1  0x000070000ff782b0 in ?? ()
#2  0x0000000000000012 in ?? ()
#3  0x000070000ff782d0 in ?? ()
#4  0x00000001000a2006 in opencv::opencv::hub::core::write_sparsemat (fs=0x0, name=..., value=0x0)
    at /Users/framp/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.46.3/src/opencv/hub/core.rs:6241
#5  0x000070000ff78308 in ?? ()
#6  0x0000000000000012 in ?? ()
#7  0x000070000ff78308 in ?? ()
#8  0x0000000000000012 in ?? ()
#9  0x000070000ff78380 in ?? ()
#10 0x00000001000a48e4 in opencv::opencv::hub::core::FileStorage::new (filename=..., flags=0, encoding=...)
    at /Users/framp/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.46.3/src/opencv/hub/core.rs:7861
#11 0x0000000174cf8000 in ?? ()
#12 0x00000000007a8000 in ?? ()
#13 0x0000000000000012 in ?? ()
#14 0x000070000ff783c0 in ?? ()
#15 0x00000000007a8000 in ?? ()
#16 0x0000000174cf8000 in ?? ()
#17 0x0000000174cf8000 in ?? ()
#18 0x00000000007a8000 in ?? ()
#19 0x000070000ff78380 in ?? ()
#20 0x00000001000a2387 in opencv::opencv::hub::core::write_str (fs=0x0, name=..., value=...)
    at /Users/framp/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.46.3/src/opencv/hub/core.rs:6247
#21 0x00000000007a8000 in ?? ()
#22 0x0000000174cf8000 in ?? ()
#23 0x00000000007a8000 in ?? ()
#24 0x0000000174cf8000 in ?? ()
#25 0x000070000ff783d8 in ?? ()
#26 0x0000000110b04410 in ?? ()
#27 0x000001000ff783d8 in ?? ()
#28 0x0000000155004ce0 in ?? ()
#29 0x0000000174cf8000 in ?? ()
#30 0x00000000007a8000 in ?? ()
#31 0x000070000ff78410 in ?? ()
#32 0x00000001000a431f in opencv::opencv::hub::core::FileNode::new (fs=0x155004ce0, block_idx=123145570190000, ofs=18)
    at /Users/framp/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.46.3/src/opencv/hub/core.rs:7440
#33 0x0000000000000000 in ?? ()

I'll keep on digging in the code to see how I got to a call to FileStorage::new but I'd appreciate some ideas on what could have gone wrong

@twistedfall
Copy link
Owner

That’s extremely weird, at no point this code should create threads or call FileStorage API. Will you be able to create a minimum reproducible example that I can run locally? I’ve got a debug build of OpenCV so the backtrace will be more clear.

@framp
Copy link
Author

framp commented Dec 6, 2020

This ended up being caused by another dependency, it just happened to find opencv functions at those memory addresses

Thanks for confirming I wasn't missing something OpenCV related and sorry for the noise!

@framp framp closed this as completed Dec 6, 2020
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

No branches or pull requests

2 participants