]> wimlib.net Git - wimlib/blobdiff - src/decompress.c
Prevent huge memory allocations from fuzzed header fields
[wimlib] / src / decompress.c
index d79865b898d19e9409f47569531aa0ef5f38454b..974483c3ef016f600c724e171fe8f60452b6e972 100644 (file)
@@ -36,7 +36,7 @@ struct wimlib_decompressor {
        void *private;
 };
 
-static const struct decompressor_ops *decompressor_ops[] = {
+static const struct decompressor_ops * const decompressor_ops[] = {
        [WIMLIB_COMPRESSION_TYPE_XPRESS] = &xpress_decompressor_ops,
        [WIMLIB_COMPRESSION_TYPE_LZX]    = &lzx_decompressor_ops,
        [WIMLIB_COMPRESSION_TYPE_LZMS]   = &lzms_decompressor_ops,
@@ -56,6 +56,11 @@ wimlib_create_decompressor(enum wimlib_compression_type ctype,
                           struct wimlib_decompressor **dec_ret)
 {
        struct wimlib_decompressor *dec;
+       int ret;
+
+       ret = wimlib_global_init(0);
+       if (ret)
+               return ret;
 
        if (!decompressor_ctype_valid(ctype))
                return WIMLIB_ERR_INVALID_COMPRESSION_TYPE;
@@ -73,8 +78,6 @@ wimlib_create_decompressor(enum wimlib_compression_type ctype,
        dec->max_block_size = max_block_size;
        dec->private = NULL;
        if (dec->ops->create_decompressor) {
-               int ret;
-
                ret = dec->ops->create_decompressor(max_block_size,
                                                    &dec->private);
                if (ret) {