+static u64
+lzms_get_needed_memory(size_t max_block_size,
+ const struct wimlib_compressor_params_header *_params)
+{
+ const struct wimlib_lzms_compressor_params *params = lzms_get_params(_params);
+
+ u64 size = 0;
+
+ size += max_block_size;
+ size += sizeof(struct lzms_compressor);
+ size += lz_sarray_get_needed_memory(max_block_size);
+ size += lz_match_chooser_get_needed_memory(params->optim_array_length,
+ params->nice_match_length,
+ params->max_match_length);
+ size += min(params->max_match_length -
+ params->min_match_length + 1,
+ params->max_matches_per_pos) *
+ sizeof(((struct lzms_compressor*)0)->matches[0]);
+ return size;
+}
+
+static bool
+lzms_params_valid(const struct wimlib_compressor_params_header *_params)
+{
+ const struct wimlib_lzms_compressor_params *params =
+ (const struct wimlib_lzms_compressor_params*)_params;
+
+ if (params->hdr.size != sizeof(*params) ||
+ params->max_match_length < params->min_match_length ||
+ params->min_match_length < 2 ||
+ params->optim_array_length == 0 ||
+ min(params->max_match_length, params->nice_match_length) > 65536)
+ return false;
+
+ return true;
+}
+