diff --git a/blosc/b2nd_utils.c b/blosc/b2nd_utils.c index 10aa6ec7..3c8e354a 100644 --- a/blosc/b2nd_utils.c +++ b/blosc/b2nd_utils.c @@ -332,7 +332,7 @@ int b2nd_copy_buffer(int8_t ndim, const void *src, const int64_t *src_pad_shape, const int64_t *src_start, const int64_t *src_stop, void *dst, const int64_t *dst_pad_shape, - const int64_t *dst_start) __attribute__((deprecated("Use b2nd_copy_buffer2 instead"))) { + const int64_t *dst_start) { // Simply cast itemsize to int32_t and delegate return b2nd_copy_buffer2(ndim, (int32_t)itemsize, src, src_pad_shape, src_start, src_stop, dst, dst_pad_shape, dst_start); diff --git a/blosc/blosc2.c b/blosc/blosc2.c index b0890021..89ead00a 100644 --- a/blosc/blosc2.c +++ b/blosc/blosc2.c @@ -2266,6 +2266,12 @@ static int initialize_context_compression( } /* Check typesize limits */ + if (context->typesize > BLOSC2_MAXTYPESIZE) { + // If typesize is too large for Blosc2, return an error + BLOSC_TRACE_ERROR("Typesize cannot exceed %d bytes.", BLOSC2_MAXTYPESIZE); + return BLOSC2_ERROR_INVALID_PARAM; + } + /* Now, cap typesize so that blosc2 split machinery can continue to work */ if (context->typesize > BLOSC_MAX_TYPESIZE) { /* If typesize is too large, treat buffer as an 1-byte stream. */ context->typesize = 1; diff --git a/include/b2nd.h b/include/b2nd.h index 354cfaf6..71bff42e 100644 --- a/include/b2nd.h +++ b/include/b2nd.h @@ -574,7 +574,8 @@ BLOSC_EXPORT int b2nd_copy_buffer(int8_t ndim, const void *src, const int64_t *src_pad_shape, const int64_t *src_start, const int64_t *src_stop, void *dst, const int64_t *dst_pad_shape, - const int64_t *dst_start); + const int64_t *dst_start) + __attribute__((deprecated("Use b2nd_copy_buffer2 instead"))); /** diff --git a/include/blosc2.h b/include/blosc2.h index c2d472c6..c3b0c287 100644 --- a/include/blosc2.h +++ b/include/blosc2.h @@ -291,7 +291,8 @@ enum { */ enum { BLOSC2_MAXDICTSIZE = 128 * 1024, //!< maximum size for compression dicts - BLOSC2_MAXBLOCKSIZE = 536866816 //!< maximum size for blocks + BLOSC2_MAXBLOCKSIZE = 536866816, //!< maximum size for blocks + BLOSC2_MAXTYPESIZE = BLOSC2_MAXBLOCKSIZE, //!< maximum size for types }; diff --git a/tests/b2nd/test_b2nd_copy_buffer.c b/tests/b2nd/test_b2nd_copy_buffer.c index 6958a3bc..a71d1248 100644 --- a/tests/b2nd/test_b2nd_copy_buffer.c +++ b/tests/b2nd/test_b2nd_copy_buffer.c @@ -26,7 +26,7 @@ CUTEST_TEST_SETUP(copy_buffer) { CUTEST_TEST_TEST(copy_buffer) { const int8_t ndim = 3; - const uint8_t itemsize = sizeof(uint8_t); + const int32_t itemsize = sizeof(uint8_t); const int64_t chunk_shape[] = {3, 3, 1}; @@ -51,24 +51,10 @@ CUTEST_TEST_TEST(copy_buffer) { 0, 0}; const int64_t dest_shape[] = {2, 2, 2}; - B2ND_TEST_ASSERT(b2nd_copy_buffer(ndim, itemsize, - chunk0x, chunk_shape, chunk0s_start, chunk0s_stop, - dest, dest_shape, chunk0s_dest)); - B2ND_TEST_ASSERT(b2nd_copy_buffer(ndim, itemsize, - chunk1x, chunk_shape, chunk1s_start, chunk1s_stop, - dest, dest_shape, chunk1s_dest)); - - for (int i = 0; i < result_length; ++i) { - uint8_t a = dest[i]; - uint8_t b = result[i]; - CUTEST_ASSERT("Elements are not equal!", a == b); - } - - int32_t itemsize2 = itemsize; - B2ND_TEST_ASSERT(b2nd_copy_buffer2(ndim, itemsize2, + B2ND_TEST_ASSERT(b2nd_copy_buffer2(ndim, itemsize, chunk0x, chunk_shape, chunk0s_start, chunk0s_stop, dest, dest_shape, chunk0s_dest)); - B2ND_TEST_ASSERT(b2nd_copy_buffer2(ndim, itemsize2, + B2ND_TEST_ASSERT(b2nd_copy_buffer2(ndim, itemsize, chunk1x, chunk_shape, chunk1s_start, chunk1s_stop, dest, dest_shape, chunk1s_dest));