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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015eAE2K7i5JGDwgwifiCfuA
(cherry picked from commit dd1af9576c)
This commit is contained in:
2026-09-19 19:11:42 +02:00
parent 8f2c6b10cc
commit 86ea443af0
+2 -2
View File
@@ -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) {