]> wimlib.net Git - wimlib/blobdiff - src/xpress_compress.c
Ensure validity of max_search_depth
[wimlib] / src / xpress_compress.c
index 65c4b026627bdeaf912b29e04cdba435779f7cef..1c824a57634520cdd3974e32ef88cfbe47cf7aa6 100644 (file)
@@ -1088,6 +1088,13 @@ xpress_create_compressor(size_t max_bufsize, unsigned compression_level,
                        c->impl = xpress_compress_lazy;
                        c->max_search_depth = (compression_level * 24) / 32;
                        c->nice_match_length = (compression_level * 48) / 32;
+
+                       /* xpress_compress_lazy() needs max_search_depth >= 2
+                        * because it halves the max_search_depth when
+                        * attempting a lazy match, and max_search_depth cannot
+                        * be 0.  */
+                       if (c->max_search_depth < 2)
+                               c->max_search_depth = 2;
                }
        }
 #if SUPPORT_NEAR_OPTIMAL_PARSING
@@ -1113,6 +1120,10 @@ xpress_create_compressor(size_t max_bufsize, unsigned compression_level,
        }
 #endif /* SUPPORT_NEAR_OPTIMAL_PARSING */
 
+       /* max_search_depth == 0 is invalid.  */
+       if (c->max_search_depth < 1)
+               c->max_search_depth = 1;
+
        *c_ret = c;
        return 0;