:: commit ccc79dff295143b5238d7d4d6caa8644bcef95e6

Kamila Szewczyk <kspalaiologos@gmail.com> — 2022-05-12 07:55

parents: 855b3da084

bigger max size margin

diff --git a/etc/bitflip.c b/etc/bitflip.c
index 658b000..9ddc48d 100644
--- a/etc/bitflip.c
+++ b/etc/bitflip.c
@@ -35,7 +35,7 @@ int main(void) {
     if (!s) { printf("error in bz3_new.\n"); return 1; }
     int32_t len = bz3_encode_block(s, buf, size);
     if (len < 0) { printf("error in bz3_compress. %s.\n", bz3_strerror(s)); return 1; }
-    new_buf = malloc(size + size / 5 + 16);
+    new_buf = malloc(size + size / 50 + 32);
     if (!new_buf) { perror("malloc"); return 1; }
     orig_size = size;
     new_size = len;
diff --git a/include/libbz3.h b/include/libbz3.h
index 1e69c5c..2912546 100644
--- a/include/libbz3.h
+++ b/include/libbz3.h
@@ -55,14 +55,14 @@ void bz3_free(struct bz3_state * state);
 
 /**
  * @brief Encode a single block. Returns the amount of bytes written to `buffer'.
- * `buffer' must be able to hold at least `size + size / 50 + 16' bytes. The size must not
+ * `buffer' must be able to hold at least `size + size / 50 + 32' bytes. The size must not
  * exceed the block size associated with the state.
  */
 int32_t bz3_encode_block(struct bz3_state * state, uint8_t * buffer, int32_t size);
 
 /**
  * @brief Decode a single block.
- * `buffer' must be able to hold at least `size + size / 50 + 16' bytes. The size must not exceed
+ * `buffer' must be able to hold at least `size + size / 50 + 32' bytes. The size must not exceed
  * the block size associated with the state.
  * @param size The size of the compressed data in `buffer'
  * @param orig_size The original size of the data before compression.
diff --git a/src/libbz3.c b/src/libbz3.c
index 50aea9f..e60224e 100644
--- a/src/libbz3.c
+++ b/src/libbz3.c
@@ -72,7 +72,7 @@ PUBLIC_API struct bz3_state * bz3_new(s32 block_size) {
 
     bz3_state->cm_state = malloc(sizeof(state));
 
-    bz3_state->swap_buffer = malloc(block_size + block_size / 50 + 16);
+    bz3_state->swap_buffer = malloc(block_size + block_size / 50 + 32);
     bz3_state->sais_array = malloc(block_size * sizeof(s32));
 
     bz3_state->lzp_lut = calloc(1 << LZP_DICTIONARY, sizeof(s32));
@@ -186,7 +186,7 @@ PUBLIC_API s32 bz3_decode_block(struct bz3_state * state, u8 * buffer, s32 data_
     u32 crc32 = read_neutral_s32(buffer);
     s32 bwt_idx = read_neutral_s32(buffer + 4);
 
-    if(data_size > state->block_size + state->block_size / 50 + 16 || data_size < 0) {
+    if(data_size > state->block_size + state->block_size / 50 + 32 || data_size < 0) {
         state->last_error = BZ3_ERR_MALFORMED_HEADER;
         return -1;
     }
@@ -211,13 +211,13 @@ PUBLIC_API s32 bz3_decode_block(struct bz3_state * state, u8 * buffer, s32 data_
 
     data_size -= p * 4 + 1;
 
-    if (((model & 2) && (lzp_size > state->block_size + state->block_size / 50 + 16 || lzp_size < 0)) ||
-        ((model & 4) && (rle_size > state->block_size + state->block_size / 50 + 16 || rle_size < 0))) {
+    if (((model & 2) && (lzp_size > state->block_size + state->block_size / 50 + 32 || lzp_size < 0)) ||
+        ((model & 4) && (rle_size > state->block_size + state->block_size / 50 + 32 || rle_size < 0))) {
         state->last_error = BZ3_ERR_MALFORMED_HEADER;
         return -1;
     }
 
-    if(orig_size > state->block_size + state->block_size / 50 + 16 || orig_size < 0) {
+    if(orig_size > state->block_size + state->block_size / 50 + 32 || orig_size < 0) {
         state->last_error = BZ3_ERR_MALFORMED_HEADER;
         return -1;
     }
@@ -264,7 +264,7 @@ PUBLIC_API s32 bz3_decode_block(struct bz3_state * state, u8 * buffer, s32 data_
 
     state->last_error = BZ3_OK;
 
-    if(size_src > state->block_size + state->block_size / 50 + 16 || size_src < 0) {
+    if(size_src > state->block_size + state->block_size / 50 + 32 || size_src < 0) {
         state->last_error = BZ3_ERR_MALFORMED_HEADER;
         return -1;
     }
diff --git a/src/main.c b/src/main.c
index 2d5051e..f5cce49 100644
--- a/src/main.c
+++ b/src/main.c
@@ -252,7 +252,7 @@ int main(int argc, char * argv[]) {
             return 1;
         }
 
-        u8 * buffer = malloc(block_size + block_size / 50 + 16);
+        u8 * buffer = malloc(block_size + block_size / 50 + 32);
 
         if (!buffer) {
             fprintf(stderr, "Failed to allocate memory.\n");
@@ -339,7 +339,7 @@ int main(int argc, char * argv[]) {
                 fprintf(stderr, "Failed to create a block encoder state.\n");
                 return 1;
             }
-            buffers[i] = malloc(block_size + block_size / 50 + 16);
+            buffers[i] = malloc(block_size + block_size / 50 + 32);
             if (!buffers[i]) {
                 fprintf(stderr, "Failed to allocate memory.\n");
                 return 1;
tab: 248 wrap: offon