lzms-compress.c: Fix crash on compression levels 1 through 4
authorEric Biggers <ebiggers3@gmail.com>
Sat, 2 Aug 2014 14:19:54 +0000 (09:19 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Sat, 2 Aug 2014 14:20:03 +0000 (09:20 -0500)
lzms_get_near_optimal_item() assumes that nice_match_length >=
min_match_length.

src/lzms-compress.c

index d93ce3d..b4391c2 100644 (file)
@@ -1309,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;
 }