Add a way to disable check of chunk min size
authorStefano Babic <sbabic@denx.de>
Sat, 28 Aug 2021 14:18:54 +0000 (16:18 +0200)
committerStefano Babic <sbabic@denx.de>
Tue, 31 Aug 2021 12:59:23 +0000 (14:59 +0200)
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 <sbabic@denx.de>
include/zck.h.in
src/lib/comp/comp.c
src/lib/zck.c
src/lib/zck_private.h
src/zck.c

index a053b303c43a15d7b291362dd31bde6ee20b4db7..57ee9cfa7e957b9f13bd6ea6bfdd145f8974dc27 100644 (file)
@@ -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 */
index e80e6134ef9310ab8a49ef23b52697b6cb01d13f..063475c059b28044da244ec863f7cedf8e4f4197 100644 (file)
@@ -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;
     }
index 9a81142c0ace1bcf50c90cba9b9abe3da1b1357b..6ebce9f5a264d765a4a14b4e01638840138b2f83 100644 (file)
@@ -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 */
index d21f8c55141230e2d33b4481aeb1fcfe1e1342cf..d1a40a78540f87e5e71fcea0c2fd106bcde91442 100644 (file)
@@ -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;
index 9d8f01e79d07aa979125d6b51131268adf17c3c4..a4bf7302182e575b647ad6ceda57455035b5f9bf 100644 (file)
--- 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);
         }