rust-bio / rust-htslib

This library provides HTSlib bindings and a high level Rust API for reading and writing BAM files.
MIT License
308 stars 80 forks source link

Cargo test leading to "unsafe precondition(s) violated" #442

Open ebioman opened 1 month ago

ebioman commented 1 month ago

I recently updated to 1.81.0 and while the normal compilation and everything works still fine, the cargo test leads to an error which I dont manage to get around.

thread 'tests::cluster2tree_1' panicked at library/core/src/panicking.rs:221:5:
unsafe precondition(s) violated: slice::from_raw_parts requires the pointer to be aligned and non-null, and the total size of the slice not to exceed `isize::MAX`
stack backtrace:

....
 6: rust_htslib::bcf::header::HeaderView::samples
             at ..../.cargo/registry/src/index.crates.io-6f17d22bba15001f/rust-htslib-0.47.0/src/bcf/header.rs:287:22
....

line

I tried to clean everything, building in a different environment,... always hitting that wall now.

Update:

Versions:

Interestingly, it really seems to relate only to debug builds as used in cargo test. If I run cargo test --release everything succeeds. If I compile my binary with debug vs release, the results are very different:

target/release/vcf_sv_cluster --vcf test/vcf_cluster/corner_case2.vcf  --chroms test/vcf_cluster/corner_case2.length
001165F 50852   50867   000084F 1239761 1239776 corner_case2:FID.792.2; 1   +   -   BND_PAIR

--> works as expected

target/debug/vcf_sv_cluster --vcf test/vcf_cluster/corner_case2.vcf  --chroms test/vcf_cluster/corner_case2.length
thread 'main' panicked at library/core/src/panicking.rs:221:5:
unsafe precondition(s) violated: slice::from_raw_parts requires the pointer to be aligned and non-null, and the total size of the slice not to exceed `isize::MAX`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread caused non-unwinding panic. aborting.
Aborted (core dumped)

I dont know how this is possible at the moment