From 86ea443af00a9884f7195ef48d79a5fd5957d0df Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Sat, 19 Sep 2026 14:31:36 +0200 Subject: [PATCH] writer: GetCompressionAlgorithm passed a byte count as the filter-parameter count H5Pget_filter2 takes cd_nelmts as the number of elements the cd_values buffer can hold and writes up to that many. It was given sizeof(cd_values) = 32 for an 8-element array, so a filter carrying more than 8 parameters would have been written past the end of the buffer. Bitshuffle carries 5, so nothing overflowed in practice. The "Weird value" message printed cd_values[1] while the test above it is on cd_values[4]. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_015eAE2K7i5JGDwgwifiCfuA (cherry picked from commit dd1af9576c04fd2206eb4c266ab52e48b3a9a079) --- writer/HDF5Objects.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/writer/HDF5Objects.cpp b/writer/HDF5Objects.cpp index dd7e2393e..3b0f8beae 100644 --- a/writer/HDF5Objects.cpp +++ b/writer/HDF5Objects.cpp @@ -1009,7 +1009,7 @@ CompressionAlgorithm HDF5Dcpl::GetCompression() { return CompressionAlgorithm::NO_COMPRESSION; uint32_t cd_values[8]; - size_t cd_nelemts = sizeof(cd_values); + size_t cd_nelemts = std::size(cd_values); memset(cd_values, 0, sizeof(cd_values)); const auto filter = H5Pget_filter2(id, 0, nullptr, &cd_nelemts, cd_values, 0, nullptr, nullptr); @@ -1031,7 +1031,7 @@ CompressionAlgorithm HDF5Dcpl::GetCompression() { return CompressionAlgorithm::BSHUF_LZ4; if (cd_values[4] == BSHUF_H5_COMPRESS_ZSTD) return CompressionAlgorithm::BSHUF_ZSTD; - throw JFJochException(JFJochExceptionCategory::HDF5,"Weird value of parameter " + std::to_string(cd_values[1])); + throw JFJochException(JFJochExceptionCategory::HDF5,"Weird value of parameter " + std::to_string(cd_values[4])); } std::string ExtractFilename(const std::string& str) {