Skip to content

Commit 5f61928

Browse files
committed
Fix a regression for a last chunk with nbytes < blocksize
1 parent 486db6c commit 5f61928

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

blosc/blosc2.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,10 @@ int read_chunk_header(const uint8_t* src, int32_t srcsize, bool extended_header,
773773
else {
774774
flags_to_filters(header->flags, header->filters);
775775
}
776+
if ((header->blosc2_flags2 & BLOSC2_VL_BLOCKS) == 0 &&
777+
header->nbytes > 0 && header->blocksize > header->nbytes) {
778+
header->blocksize = header->nbytes;
779+
}
776780
return 0;
777781
}
778782

@@ -923,14 +927,19 @@ int fill_tuner(blosc2_tuner *tuner) {
923927

924928

925929
static int blosc2_intialize_header_from_context(blosc2_context* context, blosc_header* header, bool extended_header) {
930+
int32_t header_blocksize = (int32_t)(context->header_blocksize > 0 ? context->header_blocksize : context->blocksize);
931+
if ((context->blosc2_flags2 & BLOSC2_VL_BLOCKS) == 0 &&
932+
context->sourcesize > 0 && header_blocksize > context->sourcesize) {
933+
header_blocksize = (int32_t)context->sourcesize;
934+
}
926935
memset(header, 0, sizeof(blosc_header));
927936

928937
header->version = BLOSC2_VERSION_FORMAT;
929938
header->versionlz = compcode_to_compversion(context->compcode);
930939
header->flags = context->header_flags;
931940
header->typesize = (uint8_t)context->typesize;
932941
header->nbytes = (int32_t)context->sourcesize;
933-
header->blocksize = (int32_t)(context->header_blocksize > 0 ? context->header_blocksize : context->blocksize);
942+
header->blocksize = header_blocksize;
934943

935944
int little_endian = is_little_endian();
936945
if (!little_endian) {

0 commit comments

Comments
 (0)