]> wimlib.net Git - wimlib/blobdiff - src/lzms-compress.c
Make create_decompressor() checks of max_block_size consistent
[wimlib] / src / lzms-compress.c
index f417fa526d93de2ee17cd36467fdab70735960f7..21c82ea87bf9f93e2005406018960f73bb6488f6 100644 (file)
@@ -34,7 +34,6 @@
 #  include "config.h"
 #endif
 
-#include "wimlib.h"
 #include "wimlib/assert.h"
 #include "wimlib/compiler.h"
 #include "wimlib/compressor_ops.h"
@@ -873,10 +872,10 @@ lzms_match_chooser_reverse_list(struct lzms_compressor *ctx, unsigned cur_pos)
                };
 }
 
-/* This is similar to lzx_choose_near_optimal_match() in lzx-compress.c.
+/* This is similar to lzx_choose_near_optimal_item() in lzx-compress.c.
  * Read that one if you want to understand it.  */
 static struct lz_match
-lzms_get_near_optimal_match(struct lzms_compressor *ctx)
+lzms_get_near_optimal_item(struct lzms_compressor *ctx)
 {
        u32 num_matches;
        struct lz_match *matches;
@@ -1133,7 +1132,7 @@ lzms_get_near_optimal_match(struct lzms_compressor *ctx)
 static void
 lzms_encode(struct lzms_compressor *ctx)
 {
-       struct lz_match match;
+       struct lz_match item;
 
        /* Load window into the match-finder.  */
        lz_mf_load_window(ctx->mf, ctx->window, ctx->window_size);
@@ -1143,11 +1142,11 @@ lzms_encode(struct lzms_compressor *ctx)
        ctx->optimum_end_idx = 0;
 
        while (ctx->cur_window_pos != ctx->window_size) {
-               match = lzms_get_near_optimal_match(ctx);
-               if (match.len <= 1)
+               item = lzms_get_near_optimal_item(ctx);
+               if (item.len <= 1)
                        lzms_encode_literal(ctx, ctx->window[ctx->cur_window_pos]);
                else
-                       lzms_encode_lz_match(ctx, match.len, match.offset);
+                       lzms_encode_lz_match(ctx, item.len, item.offset);
        }
 }
 
@@ -1310,7 +1309,8 @@ lzms_build_params(unsigned int compression_level,
                  struct lzms_compressor_params *lzms_params)
 {
        lzms_params->min_match_length  = (compression_level >= 50) ? 2 : 3;
-       lzms_params->nice_match_length = ((u64)compression_level * 32) / 50;
+       lzms_params->nice_match_length = max(((u64)compression_level * 32) / 50,
+                                            lzms_params->min_match_length);
        lzms_params->max_search_depth  = ((u64)compression_level * 50) / 50;
        lzms_params->optim_array_length = 224 + compression_level * 16;
 }
@@ -1335,10 +1335,12 @@ static u64
 lzms_get_needed_memory(size_t max_block_size, unsigned int compression_level)
 {
        struct lzms_compressor_params params;
+       u64 size = 0;
 
-       lzms_build_params(compression_level, &params);
+       if (max_block_size >= INT32_MAX)
+               return 0;
 
-       u64 size = 0;
+       lzms_build_params(compression_level, &params);
 
        size += sizeof(struct lzms_compressor);
        size += max_block_size;