rust-lang / flate2-rs

DEFLATE, gzip, and zlib bindings for Rust
https://docs.rs/flate2
Apache License 2.0
891 stars 158 forks source link

`cargo test --features zlib-ng-compat --no-default-features` fails on main #299

Closed alexcrichton closed 2 years ago

alexcrichton commented 2 years ago

cc @joshtriplett this may interest you, it like the zlib-ng-compat feature is broken on main

Locally in gdb I see:

0x00005555555ea41a in _mm_load_si128 (__P=0x7fffbc0013f8) at /usr/lib/gcc/x86_64-linux-gnu/9/include/emmintrin.h:697
697       return *__P;
(gdb) bt
#0  0x00005555555ea41a in _mm_load_si128 (__P=0x7fffbc0013f8) at /usr/lib/gcc/x86_64-linux-gnu/9/include/emmintrin.h:697
#1  crc32_fold_load (fold=0x7fffbc0013f8, fold0=0x7fffb77f9ab0, fold1=0x7fffb77f9ac0, fold2=0x7fffb77f9ad0, fold3=0x7fffb77f9ae0) at /home/alex/.cargo/registry/src/github.com-1ecc6299db9ec823/libz-sys-1.1.5/src/zlib-ng/arch/x86/crc32_fold_pclmulqdq.c:228
#2  0x00005555555ea661 in crc32_fold_copy_pclmulqdq (crc=0x7fffbc0013f8, dst=0x7fffbc002b08 "",
    src=0x5555556bff34 "hello, hello!hellodecompression should fail due to requiring a dictionarythe first call to decompress should indicate a dictionary is required along with the required Adler-32 checksumthe Adler-32 che"..., len=13)
    at /home/alex/.cargo/registry/src/github.com-1ecc6299db9ec823/libz-sys-1.1.5/src/zlib-ng/arch/x86/crc32_fold_pclmulqdq.c:258

which looks like an unaligned pointer passed to the _mm_load_si128 intrinsic. This is perhaps related to a recent zlib-ng update in the libz-sys crate?

Craig-Macomber commented 2 years ago

This passes for me on main, but fails on CI. Using stable-x86_64-unknown-linux-gnu unchanged - rustc 1.60.0 (7737e0b5c 2022-04-04). This might be microarch specific, or nondeterminstic (perhaps memory layout dependent?). I'm running on a AMD Ryzen 7 2700X.

joshtriplett commented 2 years ago

I can reproduce this locally. Investigating.

joshtriplett commented 2 years ago

I tracked down the segfault issue, and it's fixed in zlib-ng upstream, by commit a39e323a4db80a57feecf2ae212c08070234050c ("Added memory alignment compensation functions for users who may be using custom allocators that don't align on the same boundary zlib-ng expects.").

I tried updating to current zlib-ng, but that resulted in a different testsuite failure, which I tracked down and reported as https://github.com/zlib-ng/zlib-ng/pull/1258 .

I'm going to submit a PR updating to a version of zlib-ng sufficiently new to fix this issue, but prior to the introduction of the new issue.

joshtriplett commented 2 years ago

Fixed in https://github.com/rust-lang/libz-sys/pull/96 .

joshtriplett commented 2 years ago

I've uploaded a fixed libz-sys.