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

prevent SIGSEGV for non-strings on read string method #284

Merged
merged 8 commits into from Aug 25, 2022

Conversation

ChristianBeilschmidt
Copy link
Contributor

@ChristianBeilschmidt ChristianBeilschmidt commented Aug 15, 2022

  • I agree to follow the project's code of conduct.
  • I added an entry to CHANGES.md if knowledge of this change could be valuable to users.

I noticed that there is a segmentation fault when calling read_as_string for the MDArray if it is not of type string.
This is why I check for its datatype first.

Moreover, there are new Clippy lints that I had to consider.

@lnicola
Copy link
Member

lnicola commented Aug 15, 2022

What's wrong with the Eq derive and should GdalError even implement PartialEq?

@ChristianBeilschmidt
Copy link
Contributor Author

What's wrong with the Eq derive and should GdalError even implement PartialEq?

PartialEq is currently derived and super practical when writing tests. However, if you have one error that is not PartialEq, e.g. from std::io, you are lost there and have to change it.

This is why I would like to not enforce Eq. Moreover, Eq already does not work for the ndarray gated error.

Then, the LTS does not know about this Lint at all… so I had to find a workaround there.


The crucial part of this PR are the spurious SIGSEGVs that sometimes occur. If I run it locally, I get these every 10-15 runs.

If I run something like

RUSTFLAGS="-Z sanitizer=memory -Zsanitizer-memory-track-origins" cargo +nightly-2022-06-16-x86_64-unknown-linux-gnu test -Z build-std --target x86_64-unknown-linux-gnu --all-features -- raster::mdarray::tests::test_array_names

I get

Uninitialized bytes in MemcmpInterceptorCommon at offset 0 inside [0x702000003040, 8)
==144725==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x55c8379013ce  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x803ce) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #1 0x7efddeac9934  (/lib/libgdal.so.30+0x10ed934) (BuildId: 965b1b7ee55bf9bdb5298fb4af151db56451b22c)
    #2 0x7efddeaf94ec  (/lib/libgdal.so.30+0x111d4ec) (BuildId: 965b1b7ee55bf9bdb5298fb4af151db56451b22c)
    #3 0x7efddeac5dbe  (/lib/libgdal.so.30+0x10e9dbe) (BuildId: 965b1b7ee55bf9bdb5298fb4af151db56451b22c)
    #4 0x7efddeac5f89  (/lib/libgdal.so.30+0x10e9f89) (BuildId: 965b1b7ee55bf9bdb5298fb4af151db56451b22c)
    #5 0x7efddeac7093  (/lib/libgdal.so.30+0x10eb093) (BuildId: 965b1b7ee55bf9bdb5298fb4af151db56451b22c)
    #6 0x7efddea83961  (/lib/libgdal.so.30+0x10a7961) (BuildId: 965b1b7ee55bf9bdb5298fb4af151db56451b22c)
    #7 0x7efddea83acf  (/lib/libgdal.so.30+0x10a7acf) (BuildId: 965b1b7ee55bf9bdb5298fb4af151db56451b22c)
    #8 0x7efdde4e4458  (/lib/libgdal.so.30+0xb08458) (BuildId: 965b1b7ee55bf9bdb5298fb4af151db56451b22c)
    #9 0x7efdde4e4544  (/lib/libgdal.so.30+0xb08544) (BuildId: 965b1b7ee55bf9bdb5298fb4af151db56451b22c)
    #10 0x7efdde053ddc  (/lib/libgdal.so.30+0x677ddc) (BuildId: 965b1b7ee55bf9bdb5298fb4af151db56451b22c)
    #11 0x55c83799cefe  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x11befe) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #12 0x55c8379b381e  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x13281e) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #13 0x55c839f0296d  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x268196d) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #14 0x55c8379b34c6  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x1324c6) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #15 0x55c837c2e8eb  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x3ad8eb) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #16 0x55c837cd2b3d  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x451b3d) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #17 0x55c837d1935e  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x49835e) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #18 0x55c837b0e095  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x28d095) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #19 0x55c837ed6fb5  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x655fb5) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #20 0x55c837ac13e2  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x2403e2) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #21 0x55c839039eb0  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x17b8eb0) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #22 0x55c83922e224  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x19ad224) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #23 0x55c83922e133  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x19ad133) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #24 0x55c839031e83  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x17b0e83) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #25 0x55c839100a0a  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x187fa0a) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #26 0x55c83910da34  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x188ca34) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #27 0x55c839128d21  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x18a7d21) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #28 0x55c83917a5a9  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x18f95a9) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #29 0x55c8391251a3  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x18a41a3) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #30 0x55c83902c50a  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x17ab50a) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #31 0x55c83922f87b  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x19ae87b) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #32 0x55c83922d660  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x19ac660) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #33 0x55c83922de52  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x19ace52) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #34 0x55c838f96391  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x1715391) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #35 0x55c839124824  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x18a3824) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #36 0x55c83910d522  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x188c522) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #37 0x55c8391288e1  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x18a78e1) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #38 0x55c83917a5a9  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x18f95a9) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #39 0x55c839125ac0  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x18a4ac0) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #40 0x55c83902c865  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x17ab865) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #41 0x55c839123f29  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x18a2f29) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #42 0x55c839032ab2  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x17b1ab2) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #43 0x55c839e9b98a  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x261a98a) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #44 0x55c839e9bcba  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x261acba) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #45 0x55c839658c85  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x1dd7c85) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #46 0x7efddd9a6608  (/lib/x86_64-linux-gnu/libpthread.so.0+0x8608) (BuildId: 7b4536f41cdaa5888408e82d0836e33dcf436466)
    #47 0x7efddd776132  (/lib/x86_64-linux-gnu/libc.so.6+0x11f132) (BuildId: 1878e6b475720c7c51969e69ab2d276fae6d1dee)

  Uninitialized value was created by a heap allocation
    #0 0x55c8378fd540  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x7c540) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c)
    #1 0x7efdda311b38  (/lib/x86_64-linux-gnu/libstdc++.so.6+0xaab38) (BuildId: c90e6603c7cdf84713cd445700a575d3ea446d9b)

SUMMARY: MemorySanitizer: use-of-uninitialized-value (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-95f474802ad15760+0x803ce) (BuildId: 0010e2250ad2ba7f4a92db43e0ed0f9ff4febf4c) 
Exiting
error: test failed, to rerun pass '--lib'

Do you or anyone know how it can pinpoint me to the problem (e.g. line of code)?
I haven't used this before.

@lnicola
Copy link
Member

lnicola commented Aug 15, 2022

PartialEq is currently derived and super practical when writing tests.

I don't think it's worth the trouble. A couple of unwrap()s in tests are going to be fine.

The crucial part of this PR are the spurious SIGSEGVs that sometimes occur. If I run it locally, I get these every 10-15 runs.

Does that happen only in this PR, but not on master?

@lnicola
Copy link
Member

lnicola commented Aug 15, 2022

I get this backtrace on every test, it might be a false positive:

running 1 test
Uninitialized bytes in __interceptor_strlen at offset 24 inside [0x7020000021a0, 25)
==334233==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x7f80729164eb in VSIFileManager::GetHandler(char const*) (/usr/lib/libgdal.so.31+0x3164eb) (BuildId: d5ca43948a126d3ccc6e0373186f43ab677c25e9)
    #1 0x7f80729169d1 in VSIStatExL (/usr/lib/libgdal.so.31+0x3169d1) (BuildId: d5ca43948a126d3ccc6e0373186f43ab677c25e9)
    #2 0x7f80731e789a in GDALDriverManager::AutoLoadDrivers() (/usr/lib/libgdal.so.31+0xbe789a) (BuildId: d5ca43948a126d3ccc6e0373186f43ab677c25e9)
    #3 0x7f8072ea8c76 in GDALAllRegister (/usr/lib/libgdal.so.31+0x8a8c76) (BuildId: d5ca43948a126d3ccc6e0373186f43ab677c25e9)
    #4 0x55a2119cd11e in gdal::driver::_register_drivers::_$u7b$$u7b$closure$u7d$$u7d$::hbe592a9f2bb886d8 /home/grayshade/Projects/georust/gdal/src/driver.rs:22:13
    #5 0x55a211ae798e in std::sync::once::Once::call_once::_$u7b$$u7b$closure$u7d$$u7d$::h8c5a879f5913a6e1 /home/grayshade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sync/once.rs:276:41
    #6 0x55a213e990ad in std::sync::once::Once::call_inner::hd45b00db8ff66d4d /home/grayshade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sync/once.rs:434:21
    #7 0x55a211ae7636 in std::sync::once::Once::call_once::hc896786934c25371 /home/grayshade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sync/once.rs:276:9
    #8 0x55a211986ceb in gdal::driver::_register_drivers::h044c3b116d743ac5 /home/grayshade/Projects/georust/gdal/src/driver.rs:21:9
    #9 0x55a211e0793d in gdal::dataset::Dataset::_open_ex::hd4f38d57a5c2493c /home/grayshade/Projects/georust/gdal/src/dataset.rs:236:9
    #10 0x55a211f25fbe in gdal::dataset::Dataset::open_ex::h2b42e2e35abcb1a2 /home/grayshade/Projects/georust/gdal/src/dataset.rs:232:9
    #11 0x55a21196ff91 in gdal::raster::mdarray::tests::test_read_string_array::hc6a1025f849fc25e /home/grayshade/Projects/georust/gdal/src/raster/mdarray.rs:754:23
    #12 0x55a211a2e975 in gdal::raster::mdarray::tests::test_read_string_array::_$u7b$$u7b$closure$u7d$$u7d$::h39a8ae2f2c26515d /home/grayshade/Projects/georust/gdal/src/raster/mdarray.rs:747:5
    #13 0x55a211b67e22 in core::ops::function::FnOnce::call_once::h0e08a4c057889930 /home/grayshade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:248:5
    #14 0x55a213026430 in core::ops::function::FnOnce::call_once::h78f67bbbc478e858 /home/grayshade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:248:5
    #15 0x55a213221614 in test::__rust_begin_short_backtrace::h424c1b00664ff9a5 /home/grayshade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/test/src/lib.rs:572:5
    #16 0x55a213221383 in test::run_test::_$u7b$$u7b$closure$u7d$$u7d$::h4b49505ef69968eb /home/grayshade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/test/src/lib.rs:563:30
    #17 0x55a21301fea3 in core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h5634564ee990e463 /home/grayshade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:248:5
    #18 0x55a2130f9814 in _$LT$alloc..boxed..Box$LT$F$C$A$GT$$u20$as$u20$core..ops..function..FnOnce$LT$Args$GT$$GT$::call_once::h77f2eedd5f93afce /home/grayshade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/boxed.rs:1935:9
    #19 0x55a21328d124 in _$LT$core..panic..unwind_safe..AssertUnwindSafe$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$$LP$$RP$$GT$$GT$::call_once::h623069be585d6273 /home/grayshade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/panic/unwind_safe.rs:271:9
    #20 0x55a213110c11 in std::panicking::try::do_call::hea3db3f94db7109e /home/grayshade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:492:40
    #21 0x55a213168349 in __rust_try test.e9b8a699-cgu.3
    #22 0x55a21310e0d3 in std::panicking::try::h76022fd79b9780a6 /home/grayshade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:456:19
    #23 0x55a212fda7ea in std::panic::catch_unwind::h7d8fa29bb3b59267 /home/grayshade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:137:14
    #24 0x55a213222acb in test::run_test_in_process::hdff1463fa940207c /home/grayshade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/test/src/lib.rs:595:18
    #25 0x55a2132208b0 in test::run_test::run_test_inner::_$u7b$$u7b$closure$u7d$$u7d$::h00d76d275d162f11 /home/grayshade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/test/src/lib.rs:489:39
    #26 0x55a2132210a2 in test::run_test::run_test_inner::_$u7b$$u7b$closure$u7d$$u7d$::hf359ab11c43d03d2 /home/grayshade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/test/src/lib.rs:516:37
    #27 0x55a212fd5a31 in std::sys_common::backtrace::__rust_begin_short_backtrace::h3dd6b1570de93ee9 /home/grayshade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys_common/backtrace.rs:122:18
    #28 0x55a2130af534 in std::thread::Builder::spawn_unchecked_::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::haadda7250bd8d3e5 /home/grayshade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/mod.rs:505:17
    #29 0x55a21328cf52 in _$LT$core..panic..unwind_safe..AssertUnwindSafe$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$$LP$$RP$$GT$$GT$::call_once::h430cdcfa434bee4f /home/grayshade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/panic/unwind_safe.rs:271:9
    #30 0x55a21310fd91 in std::panicking::try::do_call::h3a880b2671530a30 /home/grayshade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:492:40
    #31 0x55a213168349 in __rust_try test.e9b8a699-cgu.3
    #32 0x55a21310d540 in std::panicking::try::h4909ff5985009677 /home/grayshade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:456:19
    #33 0x55a212fda5c5 in std::panic::catch_unwind::h58652b814c250840 /home/grayshade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:137:14
    #34 0x55a2130aea49 in std::thread::Builder::spawn_unchecked_::_$u7b$$u7b$closure$u7d$$u7d$::h3e99447dc95bf747 /home/grayshade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/mod.rs:504:30
    #35 0x55a213020a12 in core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::hd6fa08024ac1c9fc /home/grayshade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:248:5
    #36 0x55a213e6f5e4 in _$LT$alloc..boxed..Box$LT$F$C$A$GT$$u20$as$u20$core..ops..function..FnOnce$LT$Args$GT$$GT$::call_once::hdc3b7ab0e4eb8d17 /home/grayshade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/boxed.rs:1935:9
    #37 0x55a213e6f2ef in _$LT$alloc..boxed..Box$LT$F$C$A$GT$$u20$as$u20$core..ops..function..FnOnce$LT$Args$GT$$GT$::call_once::had43e6129a688d3c /home/grayshade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/boxed.rs:1935:9
    #38 0x55a21370f6a5 in std::sys::unix::thread::Thread::new::thread_start::h49727342928fa407 /home/grayshade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/unix/thread.rs:108:17
    #39 0x7f80723b778c  (/usr/lib/libc.so.6+0x8678c) (BuildId: 7d4293a9bbe1f068ab7ae807c2d9377395eb5b41)
    #40 0x7f80724388e3 in clone (/usr/lib/libc.so.6+0x1078e3) (BuildId: 7d4293a9bbe1f068ab7ae807c2d9377395eb5b41)

  Uninitialized value was created by a heap allocation
    #0 0x55a211851550 in malloc /rustc/llvm/src/llvm-project/compiler-rt/lib/msan/msan_interceptors.cpp:895:3
    #1 0x7f80700a647c in operator new(unsigned long) /usr/src/debug/gcc/libstdc++-v3/libsupc++/new_op.cc:50:22
    #2 0x55a211846fc4 in __msan_test_shadow /rustc/llvm/src/llvm-project/compiler-rt/lib/msan/msan.cpp:527:7
    #3 0x7f80733fd8e3  (/usr/lib/libgdal.so.31+0xdfd8e3) (BuildId: d5ca43948a126d3ccc6e0373186f43ab677c25e9)

SUMMARY: MemorySanitizer: use-of-uninitialized-value (/usr/lib/libgdal.so.31+0x3164eb) (BuildId: d5ca43948a126d3ccc6e0373186f43ab677c25e9) in VSIFileManager::GetHandler(char const*)
Exiting

@ChristianBeilschmidt
Copy link
Contributor Author

PartialEq is currently derived and super practical when writing tests.

I don't think it's worth the trouble. A couple of unwrap()s in tests are going to be fine.

Okay, agreed, but should I really remove PartialEq from GdalError in this PR?

The crucial part of this PR are the spurious SIGSEGVs that sometimes occur. If I run it locally, I get these every 10-15 runs.

Does that happen only in this PR, but not on master?

I just added a new check, so this should happen on master. This is why I am looking into this because we thought (on Discord) of releasing a new version 😄 . Strangely, similar code runs without SIGSEGVs in Geo Engine. I basically wanted to switch it to this code, once released.


You've got a nicer backtrace for your memory checks, could you post your run command?

@ChristianBeilschmidt
Copy link
Contributor Author

PartialEq is currently derived and super practical when writing tests.

I don't think it's worth the trouble. A couple of unwrap()s in tests are going to be fine.

Okay, agreed, but should I really remove PartialEq from GdalError in this PR?

The crucial part of this PR are the spurious SIGSEGVs that sometimes occur. If I run it locally, I get these every 10-15 runs.

Does that happen only in this PR, but not on master?

I just added a new check, so this should happen on master. This is why I am looking into this because we thought (on Discord) of releasing a new version smile . Strangely, similar code runs without SIGSEGVs in Geo Engine. I basically wanted to switch it to this code, once released.

You've got a nicer backtrace for your memory checks, could you post your run command?

I've merged the other PR into this, so we can focus on the MD stuff.

@lnicola You've got a nicer backtrace for your memory checks, could you post your run command?

@lnicola
Copy link
Member

lnicola commented Aug 17, 2022

I used the same command as you (maybe with a different nightly, rustc 1.64.0-nightly (affe0d3a0 2022-08-05)). It might be some OS thing, I'm not sure.

The point is, that's reported in GDAL itself, in GDALAllRegister. I think it's a false positive. I haven't looked closely at the code in this PR, or in what appears to be the test that's failing for you (test_read_string_array).

Unfortunately, I'll be AFK for the next couple of days.

EDIT: you can also try ASAN and Valgrind. In my experience, ASAN catches more of the "really bad stuff", Valgrind has some "false" positives too. I tried Valgrind on test_read_string_array and I think it came out clean on master.

@ChristianBeilschmidt
Copy link
Contributor Author

So, all I did add was an additional check that we only use read_as_string when it is actually a string.

I've created the following script

#!/bin/bash

export RUSTFLAGS=-Zsanitizer=address RUSTDOCFLAGS=-Zsanitizer=address

while [ $? -eq 0 ]; do
    sleep 1

    cargo +nightly-2022-08-17-x86_64-unknown-linux-gnu test -Zbuild-std --target x86_64-unknown-linux-gnu -- raster::mdarray::tests
done

And this gets some SEGV after 10-30 calls:

running 14 tests
test raster::mdarray::tests::test_root_group_name ... ok
test raster::mdarray::tests::test_array_names ... ok
AddressSanitizer:DEADLYSIGNAL
=================================================================
test raster::mdarray::tests::test_no_data_value ... ==75256==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000040 (pc 0x7ff028740271 bp 0x000000000000 sp 0x7ff016ca0378 T11)
ok
==75256==The signal is caused by a READ memory access.
==75256==Hint: address points to the zero page.
test raster::mdarray::tests::test_read_as_string_array_for_non_string ... ok
    #0 0x7ff028740271  (/lib/x86_64-linux-gnu/libhdf5_serial.so.103+0xe6271) (BuildId: 544bb1e5cd401326097f2eac0d838f3af6f0b0a8)
    #1 0x7ff0288f256f  (/lib/x86_64-linux-gnu/libhdf5_serial.so.103+0x29856f) (BuildId: 544bb1e5cd401326097f2eac0d838f3af6f0b0a8)
    #2 0x7ff0288913cb  (/lib/x86_64-linux-gnu/libhdf5_serial.so.103+0x2373cb) (BuildId: 544bb1e5cd401326097f2eac0d838f3af6f0b0a8)
    #3 0x7ff02888591f  (/lib/x86_64-linux-gnu/libhdf5_serial.so.103+0x22b91f) (BuildId: 544bb1e5cd401326097f2eac0d838f3af6f0b0a8)
    #4 0x7ff028709572  (/lib/x86_64-linux-gnu/libhdf5_serial.so.103+0xaf572) (BuildId: 544bb1e5cd401326097f2eac0d838f3af6f0b0a8)
    #5 0x7ff028709735  (/lib/x86_64-linux-gnu/libhdf5_serial.so.103+0xaf735) (BuildId: 544bb1e5cd401326097f2eac0d838f3af6f0b0a8)
    #6 0x7ff0286e320f  (/lib/x86_64-linux-gnu/libhdf5_serial.so.103+0x8920f) (BuildId: 544bb1e5cd401326097f2eac0d838f3af6f0b0a8)
    #7 0x7ff028a40038  (/lib/x86_64-linux-gnu/libnetcdf.so.15+0x69038) (BuildId: 247fe0977349435c36af618374beb5458b40a0a0)
    #8 0x7ff028a3d077  (/lib/x86_64-linux-gnu/libnetcdf.so.15+0x66077) (BuildId: 247fe0977349435c36af618374beb5458b40a0a0)
    #9 0x7ff028a432d0  (/lib/x86_64-linux-gnu/libnetcdf.so.15+0x6c2d0) (BuildId: 247fe0977349435c36af618374beb5458b40a0a0)
    #10 0x7ff0289fe776  (/lib/x86_64-linux-gnu/libnetcdf.so.15+0x27776) (BuildId: 247fe0977349435c36af618374beb5458b40a0a0)
    #11 0x7ff0289fe7b6  (/lib/x86_64-linux-gnu/libnetcdf.so.15+0x277b6) (BuildId: 247fe0977349435c36af618374beb5458b40a0a0)
    #12 0x7ff02a38e107  (/lib/libgdal.so.30+0x86e107) (BuildId: 965b1b7ee55bf9bdb5298fb4af151db56451b22c)
    #13 0x7ff02a38ec8d  (/lib/libgdal.so.30+0x86ec8d) (BuildId: 965b1b7ee55bf9bdb5298fb4af151db56451b22c)
    #14 0x7ff02a6530d0  (/lib/libgdal.so.30+0xb330d0) (BuildId: 965b1b7ee55bf9bdb5298fb4af151db56451b22c)
    #15 0x56460aea853e  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0x4fa53e) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #16 0x56460ae62752  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0x4b4752) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #17 0x56460ade9409  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0x43b409) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #18 0x56460af0e0e9  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0x5600e9) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #19 0x56460b8769ba  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0xec89ba) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #20 0x56460b96dc2a  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0xfbfc2a) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #21 0x56460b96d7f9  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0xfbf7f9) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #22 0x56460b86ac10  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0xebcc10) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #23 0x56460b8dd068  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0xf2f068) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #24 0x56460b8dfd4d  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0xf31d4d) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #25 0x56460b8ecbc5  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0xf3ebc5) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #26 0x56460b9157aa  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0xf677aa) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #27 0x56460b8eb6e3  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0xf3d6e3) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #28 0x56460b845040  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0xe97040) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #29 0x56460b96e746  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0xfc0746) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #30 0x56460b96cde3  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0xfbede3) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #31 0x56460b96d4b7  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0xfbf4b7) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #32 0x56460b9e7e44  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0x1039e44) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #33 0x56460b8eadfa  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0xf3cdfa) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #34 0x56460b8dfdae  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0xf31dae) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #35 0x56460b8ed31b  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0xf3f31b) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #36 0x56460b9157aa  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0xf677aa) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #37 0x56460b8ebaec  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0xf3daec) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #38 0x56460b844f0e  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0xe96f0e) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #39 0x56460b8ea6e6  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0xf3c6e6) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #40 0x56460b86a10e  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0xebc10e) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #41 0x56460bf71798  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0x15c3798) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #42 0x56460bf71aa6  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0x15c3aa6) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #43 0x56460bbab688  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0x11fd688) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #44 0x7ff029aea608  (/lib/x86_64-linux-gnu/libpthread.so.0+0x8608) (BuildId: 7b4536f41cdaa5888408e82d0836e33dcf436466)
    #45 0x7ff0298ba132  (/lib/x86_64-linux-gnu/libc.so.6+0x11f132) (BuildId: 1878e6b475720c7c51969e69ab2d276fae6d1dee)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/lib/x86_64-linux-gnu/libhdf5_serial.so.103+0xe6271) (BuildId: 544bb1e5cd401326097f2eac0d838f3af6f0b0a8) 
Thread T11 created by T0 here:
    #0 0x56460ac3c5dc  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0x28e5dc) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #1 0x56460bbaaa37  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0x11fca37) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #2 0x56460b8e9a23  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0xf3ba23) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #3 0x56460b8e8362  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0xf3a362) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #4 0x56460b8eaf06  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0xf3cf06) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #5 0x56460b96ba05  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0xfbda05) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #6 0x56460b96a41f  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0xfbc41f) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #7 0x56460b95edb6  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0xfb0db6) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #8 0x56460b7bf8c6  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0xe118c6) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #9 0x56460b959b5e  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0xfabb5e) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #10 0x56460b95a9a7  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0xfac9a7) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #11 0x56460af53112  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0x5a5112) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #12 0x56460ad8dce3  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0x3dfce3) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #13 0x56460bf42102  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0x1594102) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #14 0x56460bf470ba  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0x15990ba) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #15 0x56460bbcfa49  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0x1221a49) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #16 0x56460bc33a6b  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0x1285a6b) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #17 0x56460bf422da  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0x15942da) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #18 0x56460bf470ba  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0x15990ba) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #19 0x56460bbcfd39  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0x1221d39) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #20 0x56460bc333d6  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0x12853d6) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #21 0x56460ad8dc3d  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0x3dfc3d) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)
    #22 0x56460af5313b  (/home/beilschmidt/git/rust-gdal/target/x86_64-unknown-linux-gnu/debug/deps/gdal-7a9fc38fd36df462+0x5a513b) (BuildId: ce039fc1ceba1dd90d5741a6e14595b29ea10f80)

==75256==ABORTING

I still have no clue how this can happen. And I don't know why you get nicer ASAN messages that point to some code 🤷 .

@lnicola
Copy link
Member

lnicola commented Aug 20, 2022

I let your script run for 20 minutes (maybe around 600 runs) and it didn't fail. Maybe it's something specific to your setup (version of GDAL or other dependencies)?

@ChristianBeilschmidt
Copy link
Contributor Author

Maybe someone else can confirm that. Then, we can merge it. But I am still confused 😄.

@jdroenner jdroenner mentioned this pull request Aug 23, 2022
6 tasks
@lnicola
Copy link
Member

lnicola commented Aug 23, 2022

What's weird is that your PR branch also crashed once with SIGSEGV on CI, didn't it?

@lnicola
Copy link
Member

lnicola commented Aug 23, 2022

Ah, yes, it does:

AddressSanitizer:DEADLYSIGNAL
=================================================================
==1306100==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000040 (pc 0x7f1c1dafae10 bp 0x7f1c207a0f9f sp 0x7f1c207a0d58 T11)
test raster::mdarray::tests::test_read_as_string_array_for_non_string ... ==1306100==The signal is caused by a READ memory access.
==1306100==Hint: address points to the zero page.
ok
    #0 0x7f1c1dafae10 in H5F_addr_decode (/usr/lib/libhdf5.so.200+0xfae10) (BuildId: e928e6d519578bc949985001081e2db55889095e)
    #1 0x7f1c1dceede8 in H5VL__native_blob_specific (/usr/lib/libhdf5.so.200+0x2eede8) (BuildId: e928e6d519578bc949985001081e2db55889095e)
    #2 0x7f1c1dcdfb97  (/usr/lib/libhdf5.so.200+0x2dfb97) (BuildId: e928e6d519578bc949985001081e2db55889095e)
    #3 0x7f1c1dce747c in H5VL_blob_specific (/usr/lib/libhdf5.so.200+0x2e747c) (BuildId: e928e6d519578bc949985001081e2db55889095e)
    #4 0x7f1c1dcd4153  (/usr/lib/libhdf5.so.200+0x2d4153) (BuildId: e928e6d519578bc949985001081e2db55889095e)
    #5 0x7f1c1dc5f4b2 in H5T__conv_vlen (/usr/lib/libhdf5.so.200+0x25f4b2) (BuildId: e928e6d519578bc949985001081e2db55889095e)
    #6 0x7f1c1dc508f0 in H5T_convert (/usr/lib/libhdf5.so.200+0x2508f0) (BuildId: e928e6d519578bc949985001081e2db55889095e)
    #7 0x7f1c1dac7f94 in H5D_get_create_plist (/usr/lib/libhdf5.so.200+0xc7f94) (BuildId: e928e6d519578bc949985001081e2db55889095e)
    #8 0x7f1c1dcef860 in H5VL__native_dataset_get (/usr/lib/libhdf5.so.200+0x2ef860) (BuildId: e928e6d519578bc949985001081e2db55889095e)
    #9 0x7f1c1dcd4d47  (/usr/lib/libhdf5.so.200+0x2d4d47) (BuildId: e928e6d519578bc949985001081e2db55889095e)
    #10 0x7f1c1dcdcd31 in H5VL_dataset_get (/usr/lib/libhdf5.so.200+0x2dcd31) (BuildId: e928e6d519578bc949985001081e2db55889095e)
    #11 0x7f1c1daa087c in H5Dget_create_plist (/usr/lib/libhdf5.so.200+0xa087c) (BuildId: e928e6d519578bc949985001081e2db55889095e)
    #12 0x7f1c1dead1a3 in nc4_get_var_meta (/usr/lib/libnetcdf.so.19+0xad1a3) (BuildId: 48973e4b6f0222041f0c5c3f1146768570870e69)
    #13 0x7f1c1dead920 in nc4_hdf5_find_grp_var_att (/usr/lib/libnetcdf.so.19+0xad920) (BuildId: 48973e4b6f0222041f0c5c3f1146768570870e69)
    #14 0x7f1c1deb3f37 in NC4_HDF5_inq_var_all (/usr/lib/libnetcdf.so.19+0xb3f37) (BuildId: 48973e4b6f0222041f0c5c3f1146768570870e69)
    #15 0x7f1c1de2fc96 in nc_inq_var (/usr/lib/libnetcdf.so.19+0x2fc96) (BuildId: 48973e4b6f0222041f0c5c3f1146768570870e69)
    #16 0x7f1c1de2fcd7 in nc_inq_varname (/usr/lib/libnetcdf.so.19+0x2fcd7) (BuildId: 48973e4b6f0222041f0c5c3f1146768570870e69)
    #17 0x7f1c2aab7e1d  (/usr/lib/gdalplugins/gdal_netCDF.so+0x62e1d) (BuildId: 811efbab181d578fd95384e0607ddf78cf328f2d)
    #18 0x7f1c2aab0b63  (/usr/lib/gdalplugins/gdal_netCDF.so+0x5bb63) (BuildId: 811efbab181d578fd95384e0607ddf78cf328f2d)
    #19 0x7f1c2aab7711  (/usr/lib/gdalplugins/gdal_netCDF.so+0x62711) (BuildId: 811efbab181d578fd95384e0607ddf78cf328f2d)
    #20 0x7f1c30c84cdb in GDALGroupOpenMDArray (/usr/lib/libgdal.so.31+0xc84cdb) (BuildId: d5ca43948a126d3ccc6e0373186f43ab677c25e9)
    #21 0x562249b0236e in gdal::raster::mdarray::Group::open_md_array::hffd87c63c741ffb5 /home/grayshade/Projects/georust/gdal/src/raster/mdarray.rs:402:29
    #22 0x562249ce5df2 in gdal::raster::mdarray::tests::test_read_string_array::h4f15a670359d58a1 /home/grayshade/Projects/georust/gdal/src/raster/mdarray.rs:770:28
    #23 0x562249cdc119 in gdal::raster::mdarray::tests::test_read_string_array::_$u7b$$u7b$closure$u7d$$u7d$::hd137cf6cab56e0f9 /home/grayshade/Projects/georust/gdal/src/raster/mdarray.rs:759:5

@lnicola
Copy link
Member

lnicola commented Aug 23, 2022

This is weird. I can still reproduce it after #[ignore]-ing all tests except test_read_string_array and test_read_as_string_array_for_non_string. It even happens if I comment out the read_as_string_array calls, but not if I comment out open_md_array. And it still happens with -j1.

@ChristianBeilschmidt
Copy link
Contributor Author

Well, I have no clue how this PR could lead to that problem.
It must have been there already.

@lnicola
Copy link
Member

lnicola commented Aug 23, 2022

Yeah, I'm pretty sure that your PR only causes it because it calls the problematic function a second time.

@lnicola
Copy link
Member

lnicola commented Aug 23, 2022

TIL -j is not --test-threads 😄.

I'm able to reproduce the crash in the following test:

    #[test]
    fn test_read_string_array() {
        for _ in 0..1000 {
            let t1 = std::thread::spawn(|| {
                let dataset_options = DatasetOptions {
                    open_flags: GdalOpenFlags::GDAL_OF_MULTIDIM_RASTER,
                    allowed_drivers: None,
                    open_options: None,
                    sibling_files: None,
                };
                let dataset =
                    Dataset::open_ex("fixtures/alldatatypes.nc", dataset_options).unwrap();

                let root_group = dataset.root_group().unwrap();

                let string_array = root_group
                    .open_md_array("string_var", CslStringList::new())
                    .unwrap();
            });
            let t = std::thread::spawn(|| {
                let dataset_options = DatasetOptions {
                    open_flags: GdalOpenFlags::GDAL_OF_MULTIDIM_RASTER,
                    allowed_drivers: None,
                    open_options: None,
                    sibling_files: None,
                };
                let dataset =
                    Dataset::open_ex("fixtures/alldatatypes.nc", dataset_options).unwrap();
            });
            t.join().unwrap();
            t1.join().unwrap();
        }
    }

This might be some threading issue in GDAL & friends.

@lnicola
Copy link
Member

lnicola commented Aug 23, 2022

OSGeo/gdal#6253

@lnicola
Copy link
Member

lnicola commented Aug 23, 2022

@ChristianBeilschmidt if I'm not mistaken, making a copy of alldatatypes.nc and using it in one of the tests should fix the crashes. I haven't tested it yet.

(it's fine to commit a duplicate file, git will store it only once)

@ChristianBeilschmidt
Copy link
Contributor Author

Wow, you really caught the problem! 👍 Kudos for that.

That seems to do the trick for the CI, I just merged the tests: 6ad91ed

But it's good that you opened that issue in the GDAL repo. This is really strange and concerning.

@lnicola
Copy link
Member

lnicola commented Aug 24, 2022

This is really strange

Not that strange, given that the approach netcdf takes to threading is a global mutex: https://www.unidata.ucar.edu/blogs/developer/en/entry/implementing-thread-safe-access-to.

@lnicola
Copy link
Member

lnicola commented Aug 24, 2022

What about read_into_slice and maybe others? Shouldn't they check the type too, or at least be marked as unsafe?

@ChristianBeilschmidt
Copy link
Contributor Author

What about read_into_slice and maybe others? Shouldn't they check the type too, or at least be marked as unsafe?

The problem with read as string is that we treat the result as string pointers and dereference them.
This is catastrophic if the resulting values are not pointers to strings.

This happens here:

let string = _string(string_ptr);

I don't see it happen in other places. There could be maybe another issue that you are referring to, but this PR fixes the string pointer issue.

@lnicola
Copy link
Member

lnicola commented Aug 24, 2022

There could be maybe another issue that you are referring to, but this PR fixes the string pointer issue.

I'm not saying it doesn't, I'm only saying that the implementation is still unsafe. Try this under ASAN:

            let string_array = root_group
                .open_md_array("uint_var", CslStringList::new())
                .unwrap();

            let values = string_array.read_as::<u8>(vec![0, 0], vec![1, 2]).unwrap();

This happens because GDALMDArrayRead takes the buffer type as argument, but we're passing GDALMDArrayGetDataType(self.c_mdarray), which is the array type. Normally, GDAL does some format conversions when needed. When we call GDALRasterIOEx, we pass T::gdal_type() instead.

@ChristianBeilschmidt
Copy link
Contributor Author

There could be maybe another issue that you are referring to, but this PR fixes the string pointer issue.

I'm not saying it doesn't, I'm only saying that the implementation is still unsafe. Try this under ASAN:

            let string_array = root_group
                .open_md_array("uint_var", CslStringList::new())
                .unwrap();

            let values = string_array.read_as::<u8>(vec![0, 0], vec![1, 2]).unwrap();

This happens because GDALMDArrayRead takes the buffer type as argument, but we're passing GDALMDArrayGetDataType(self.c_mdarray), which is the array type. Normally, GDAL does some format conversions when needed. When we call GDALRasterIOEx, we pass T::gdal_type() instead.

Valid point, but I would look at this in a different PR:
#290

@lnicola
Copy link
Member

lnicola commented Aug 24, 2022

Sure, but let's wait until tomorrow in case anyone else wants to take a look.

@lnicola
Copy link
Member

lnicola commented Aug 25, 2022

bors r+

@bors
Copy link
Contributor

bors bot commented Aug 25, 2022

Build succeeded:

@bors bors bot merged commit 257b95c into georust:master Aug 25, 2022
bors bot added a commit that referenced this pull request Sep 2, 2022
293: enforce that `GdalError` is `Send` r=jdroenner a=ChristianBeilschmidt

- [X] I agree to follow the project's [code of conduct](https://github.com/georust/gdal/blob/master/CODE_OF_CONDUCT.md).
- [x] I added an entry to `CHANGES.md` if knowledge of this change could be valuable to users.
---

Before #284, `GdalError` was `Send`.
The previous PR changed it unknowingly.

This PR changes #284 so that `GdalError` is `Send` again.
Moreover, it adds a test that ensures that.

Co-authored-by: Christian Beilschmidt <christian.beilschmidt@geoengine.de>
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.

None yet

2 participants