:: commit f6bda22b4092ba2388eab71741942421ae097b69

Kamila Szewczyk <kspalaiologos@gmail.com> — 2022-05-13 07:38

parents: f3dda73888

further reduce max block size

diff --git a/include/libbz3.h b/include/libbz3.h
index 4cdc860..a5ac58a 100644
--- a/include/libbz3.h
+++ b/include/libbz3.h
@@ -45,7 +45,7 @@ const char * bz3_strerror(struct bz3_state * state);
 /**
  * @brief Construct a new block encoder state, which will encode blocks as big as the given block size.
  * The decoder will be able to decode blocks at most as big as the given block size.
- * Returns NULL in case allocation fails.
+ * Returns NULL in case allocation fails or the block size is not between 65K and 511M
  */
 struct bz3_state * bz3_new(int32_t block_size);
 
diff --git a/src/libbz3.c b/src/libbz3.c
index da2b0cc..f667a6c 100644
--- a/src/libbz3.c
+++ b/src/libbz3.c
@@ -64,6 +64,10 @@ PUBLIC_API const char * bz3_strerror(struct bz3_state * state) {
 }
 
 PUBLIC_API struct bz3_state * bz3_new(s32 block_size) {
+    if (block_size < KiB(65) || block_size > MiB(511)) {
+        return NULL;
+    }
+
     struct bz3_state * bz3_state = malloc(sizeof(struct bz3_state));
 
     if (!bz3_state) {
diff --git a/src/main.c b/src/main.c
index cb3d47c..c4220b2 100644
--- a/src/main.c
+++ b/src/main.c
@@ -198,8 +198,8 @@ int main(int argc, char * argv[]) {
         output_des = stdout;
     }
 
-    if (block_size < KiB(65) || block_size > MiB(1023)) {
-        fprintf(stderr, "Block size must be between 65 KiB and 1023 MiB.\n");
+    if (block_size < KiB(65) || block_size > MiB(511)) {
+        fprintf(stderr, "Block size must be between 65 KiB and 511 MiB.\n");
         return 1;
     }
 
@@ -230,7 +230,7 @@ int main(int argc, char * argv[]) {
             fread(byteswap_buf, 4, 1, input_des);
             block_size = read_neutral_s32(byteswap_buf);
 
-            if (block_size < KiB(65) || block_size > MiB(1023)) {
+            if (block_size < KiB(65) || block_size > MiB(511)) {
                 fprintf(stderr,
                         "The input file is corrupted. Reason: Invalid block "
                         "size in the header.\n");
tab: 248 wrap: offon