From a9ed71399b5b0c973fe0a476486137512964d714 Mon Sep 17 00:00:00 2001 From: tfenne Date: Mon, 5 Oct 2026 16:28:31 -0600 Subject: [PATCH] Read negative compression levels correctly where char is unsigned The array schema stored each compression level in a char. char is unsigned on Linux aarch64 and other non-x86 Linux targets, so there a level of -1, GZIP's default, read back as 255 and GZIP compression failed with Z_STREAM_ERROR. The levels are now stored and read as int8_t: the bytes on disk are unchanged, and they read the same on every platform. Adds a test that GZIP's default level reads back as written. --- core/src/array/array_schema.cc | 11 ++++++----- test/src/c_api/test_array_schema_api.cc | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/core/src/array/array_schema.cc b/core/src/array/array_schema.cc index c5d9eb5..4012e3a 100644 --- a/core/src/array/array_schema.cc +++ b/core/src/array/array_schema.cc @@ -773,8 +773,8 @@ int ArraySchema::serialize( memcpy(buffer + offset, &compression, sizeof(char)); offset += sizeof(char); } - // Copy compression_level_ - char compression_level; + // Copy compression_level_. Levels can be negative, and char is unsigned on some platforms + int8_t compression_level; for(int i=0; i<=attribute_num_; ++i) { compression_level = compression_level_[i]; assert(offset + sizeof(char) <= buffer_size); @@ -790,7 +790,7 @@ int ArraySchema::serialize( offset += sizeof(char); } // Copy offsets compression_level_ - char offsets_compression_level; + int8_t offsets_compression_level; for(int i=0; i= 1L) { - char compression_level; + // Levels can be negative, and char is unsigned on some platforms + int8_t compression_level; for(int i=0; i<=attribute_num_; ++i) { assert(offset + sizeof(char) <= buffer_size); memcpy(&compression_level, buffer + offset, sizeof(char)); @@ -1218,7 +1219,7 @@ int ArraySchema::deserialize( } // Load offsets_compression_level_. Support added in array schema version 2L if (get_version() >= 2L) { - char offsets_compression_level; + int8_t offsets_compression_level; for(int i=0; i