]> wimlib.net Git - wimlib/commitdiff
wimlib_get_compressor_needed_memory(): return 0 on invalid max_block_size
authorEric Biggers <ebiggers3@gmail.com>
Wed, 20 Aug 2014 02:35:51 +0000 (21:35 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Wed, 20 Aug 2014 02:43:07 +0000 (21:43 -0500)
include/wimlib.h
src/compress.c

index 5fb9765847838a26aa9ae9c3ad75dc013cfda723..3762916acba6788db83aa61c5557151a54827960 100644 (file)
@@ -4455,7 +4455,8 @@ wimlib_set_default_compression_level(int ctype, unsigned int compression_level);
  * wimlib_create_compressor() for the specified compression type, maximum block
  * size, and compression level.  @p compression_level may be 0, in which case
  * the current default compression level for @p ctype is used.  Returns 0 if the
- * compression type is invalid.
+ * compression type is invalid, or the @p max_block_size for that compression
+ * type is invalid.
  */
 extern uint64_t
 wimlib_get_compressor_needed_memory(enum wimlib_compression_type ctype,
index efbd2085418f3685e8c0a52ec99c762d02e8b7ac..aed609aa7aff560a05e11a2021af3fabdb227749 100644 (file)
@@ -90,6 +90,9 @@ wimlib_get_compressor_needed_memory(enum wimlib_compression_type ctype,
        if (!compressor_ctype_valid(ctype))
                return 0;
 
+       if (max_block_size == 0)
+               return 0;
+
        ops = compressor_ops[ctype];
 
        if (compression_level == 0)
@@ -97,10 +100,16 @@ wimlib_get_compressor_needed_memory(enum wimlib_compression_type ctype,
        if (compression_level == 0)
                compression_level = DEFAULT_COMPRESSION_LEVEL;
 
-       size = sizeof(struct wimlib_compressor);
-       if (ops->get_needed_memory)
-               size += ops->get_needed_memory(max_block_size, compression_level);
-       return size;
+       if (ops->get_needed_memory) {
+               size = ops->get_needed_memory(max_block_size, compression_level);
+
+               /* 0 is never valid and indicates an invalid max_block_size.  */
+               if (size == 0)
+                       return 0;
+       } else {
+               size = 0;
+       }
+       return size + sizeof(struct wimlib_compressor);
 }
 
 WIMLIBAPI int