X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=src%2Fcompress.c;fp=src%2Fcompress.c;h=ff28ebc0f79d915701a9fdb0ef68ac47e3fbda8c;hp=47026e368d0b256afd1829fdbdc01a49e99be5b9;hb=dadccd777e56b473128d87e485fcf8565b8cb93b;hpb=d8e380e8314cdb592149a651a19690d102a1865b diff --git a/src/compress.c b/src/compress.c index 47026e36..ff28ebc0 100644 --- a/src/compress.c +++ b/src/compress.c @@ -81,12 +81,19 @@ wimlib_get_compressor_needed_memory(enum wimlib_compression_type ctype, size_t max_block_size, unsigned int compression_level) { + bool destructive; const struct compressor_ops *ops; u64 size; + destructive = (compression_level & WIMLIB_COMPRESSOR_FLAG_DESTRUCTIVE); + compression_level &= ~WIMLIB_COMPRESSOR_FLAG_DESTRUCTIVE; + if (!compressor_ctype_valid(ctype)) return 0; + if (compression_level > 0xFFFFFF) + return 0; + if (max_block_size == 0) return 0; @@ -98,7 +105,8 @@ wimlib_get_compressor_needed_memory(enum wimlib_compression_type ctype, compression_level = DEFAULT_COMPRESSION_LEVEL; if (ops->get_needed_memory) { - size = ops->get_needed_memory(max_block_size, compression_level); + size = ops->get_needed_memory(max_block_size, compression_level, + destructive); /* 0 is never valid and indicates an invalid max_block_size. */ if (size == 0) @@ -115,11 +123,18 @@ wimlib_create_compressor(enum wimlib_compression_type ctype, unsigned int compression_level, struct wimlib_compressor **c_ret) { + bool destructive; struct wimlib_compressor *c; + destructive = (compression_level & WIMLIB_COMPRESSOR_FLAG_DESTRUCTIVE); + compression_level &= ~WIMLIB_COMPRESSOR_FLAG_DESTRUCTIVE; + if (!compressor_ctype_valid(ctype)) return WIMLIB_ERR_INVALID_COMPRESSION_TYPE; + if (compression_level > 0xFFFFFF) + return WIMLIB_ERR_INVALID_PARAM; + if (c_ret == NULL) return WIMLIB_ERR_INVALID_PARAM; @@ -143,6 +158,7 @@ wimlib_create_compressor(enum wimlib_compression_type ctype, ret = c->ops->create_compressor(max_block_size, compression_level, + destructive, &c->private); if (ret) { FREE(c);