From e3fdd8210610ebe21a44a226888b519672e18986 Mon Sep 17 00:00:00 2001 From: Stefano Babic Date: Sat, 28 Aug 2021 16:18:54 +0200 Subject: [PATCH] Add a way to disable check of chunk min size The check for chunk size is done on the compressed data. This forbids to create the same chunk set in case data is not compressed and comparison is done using the hashes of original data and not of compressed chunk. Signed-off-by: Stefano Babic --- include/zck.h.in | 1 + src/lib/comp/comp.c | 4 ++-- src/lib/zck.c | 2 ++ src/lib/zck_private.h | 1 + src/zck.c | 3 ++- 5 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/zck.h.in b/include/zck.h.in index a053b30..57ee9cf 100644 --- a/include/zck.h.in +++ b/include/zck.h.in @@ -27,6 +27,7 @@ typedef enum zck_ioption { ZCK_VAL_HEADER_HASH_TYPE, /* Set what the header hash type *should* be */ ZCK_VAL_HEADER_LENGTH, /* Set what the header length *should* be */ ZCK_UNCOMP_HEADER, /* Header should contain uncompressed size, too */ + ZCK_NO_MIN_CHUNKSIZE, /* No check for min size */ ZCK_COMP_TYPE = 100, /* Set compression type using zck_comp */ ZCK_MANUAL_CHUNK, /* Disable auto-chunking */ ZCK_CHUNK_MIN, /* Minimum chunk size when manual chunking */ diff --git a/src/lib/comp/comp.c b/src/lib/comp/comp.c index e80e613..063475c 100644 --- a/src/lib/comp/comp.c +++ b/src/lib/comp/comp.c @@ -595,7 +595,7 @@ ssize_t PUBLIC zck_write(zckCtx *zck, const char *src, const size_t src_size) { "chunk"); else zck_log(ZCK_LOG_DDEBUG, "Automatically ending chunk"); - if(zck->comp.dc_data_size < zck->chunk_auto_min) { + if(!zck->no_check_min_size && zck->comp.dc_data_size < zck->chunk_auto_min) { zck_log(ZCK_LOG_DDEBUG, "Chunk too small, refusing to end chunk"); continue; @@ -618,7 +618,7 @@ ssize_t PUBLIC zck_end_chunk(zckCtx *zck) { if(!zck->comp.started && !comp_init(zck)) return -1; - if(zck->comp.dc_data_size < zck->chunk_min_size) { + if(!zck->no_check_min_size && zck->comp.dc_data_size < zck->chunk_min_size) { zck_log(ZCK_LOG_DDEBUG, "Chunk too small, refusing to end chunk"); return zck->comp.dc_data_size; } diff --git a/src/lib/zck.c b/src/lib/zck.c index 9a81142..6ebce9f 100644 --- a/src/lib/zck.c +++ b/src/lib/zck.c @@ -308,6 +308,8 @@ bool PUBLIC zck_set_ioption(zckCtx *zck, zck_ioption option, ssize_t value) { } else if(option == ZCK_UNCOMP_HEADER) { zck->has_uncompressed_source = 1; + } else if(option == ZCK_NO_MIN_CHUNKSIZE) { + zck->no_check_min_size = 1; /* Hash options */ } else if(option < 100) { /* Currently no hash options other than setting hash type, so bail */ diff --git a/src/lib/zck_private.h b/src/lib/zck_private.h index d21f8c5..d1a40a7 100644 --- a/src/lib/zck_private.h +++ b/src/lib/zck_private.h @@ -272,6 +272,7 @@ struct zckCtx { int has_streams; int has_optional_elems; int has_uncompressed_source; + int no_check_min_size; char *read_buf; size_t read_buf_size; diff --git a/src/zck.c b/src/zck.c index 9d8f01e..a4bf730 100644 --- a/src/zck.c +++ b/src/zck.c @@ -230,7 +230,8 @@ int main (int argc, char *argv[]) { } if(arguments.uncompressed) { - if(!zck_set_ioption(zck, ZCK_UNCOMP_HEADER, 1)) { + if(!zck_set_ioption(zck, ZCK_UNCOMP_HEADER, 1) || + (!zck_set_ioption(zck, ZCK_NO_MIN_CHUNKSIZE, 1))) { dprintf(STDERR_FILENO, "%s\n", zck_get_error(zck)); exit(1); } -- 2.30.2