Skip to content
New issue

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

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

Already on GitHub? # to your account

lib/x86/crc32: fix undefined behavior in VPCLMULQDQ optimized functions #404

Merged
merged 1 commit into from
Nov 27, 2024

Conversation

ebiggers
Copy link
Owner

The specifications for _mm256_castsi128_si256() and _mm512_castsi128_si512() are bugged, as they leave the high bits undefined instead of zeroed as would be expected. Separate intrinsics _mm256_zextsi128_si256() and _mm512_zextsi128_si512() were later added to allow working around this defect. Use them.

This fixes incorrect CRC checksums produced by
crc32_x86_vpclmulqdq_avx512_vl512() when built with 'clang -O0'. Other cases are not known to have been affected.

Resolves #403 Fixes: 5f2a0b4 ("lib/x86/crc32: add VPCLMULQDQ implementations of CRC-32")

The specifications for _mm256_castsi128_si256() and
_mm512_castsi128_si512() are bugged, as they leave the high bits
undefined instead of zeroed as would be expected.  Separate intrinsics
_mm256_zextsi128_si256() and _mm512_zextsi128_si512() were later added
to allow working around this defect.  Use them.

This fixes incorrect CRC checksums produced by
crc32_x86_vpclmulqdq_avx512_vl512() when built with 'clang -O0'.
Other cases are not known to have been affected.

Resolves #403
Fixes: 5f2a0b4 ("lib/x86/crc32: add VPCLMULQDQ implementations of CRC-32")
@pps83
Copy link
Contributor

pps83 commented Nov 27, 2024

tested and verified. Fix works, thanks

@pps83
Copy link
Contributor

pps83 commented Nov 27, 2024

Can you try asan, afaik it should catch that uninitialized use. llvm+asan is broken in visual studio

@ebiggers
Copy link
Owner Author

Can you try asan, afaik it should catch that uninitialized use. llvm+asan is broken in visual studio

libdeflate has been tested extensively with ASAN, MSAN, UBSAN, and valgrind. None of them can detect this case, unfortunately.

@ebiggers ebiggers merged commit 1a6f436 into master Nov 27, 2024
51 checks passed
@ebiggers ebiggers deleted the dev branch November 27, 2024 19:52
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Heisenbug in crc code when 512-bit vectors are used with Intel C++ compiler
2 participants