/*
* Copyright (C) 2013, 2014 Eric Biggers
*
- * This file is part of wimlib, a library for working with WIM files.
+ * This file is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at your option) any
+ * later version.
*
- * wimlib is free software; you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * wimlib is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- * A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * This file is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
- * You should have received a copy of the GNU General Public License
- * along with wimlib; if not, see http://www.gnu.org/licenses/.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this file; if not, see http://www.gnu.org/licenses/.
*/
#ifdef HAVE_CONFIG_H
}
WIMLIBAPI int
-wimlib_set_default_compression_level(enum wimlib_compression_type ctype,
- unsigned int compression_level)
+wimlib_set_default_compression_level(int ctype, unsigned int compression_level)
{
- if ((int)ctype == -1) {
+ if (ctype == -1) {
for (int i = 0; i < ARRAY_LEN(default_compression_levels); i++)
default_compression_levels[i] = compression_level;
} else {
if (!compressor_ctype_valid(ctype))
return 0;
+ if (max_block_size == 0)
+ return 0;
+
ops = compressor_ops[ctype];
if (compression_level == 0)
if (compression_level == 0)
compression_level = DEFAULT_COMPRESSION_LEVEL;
- size = sizeof(struct wimlib_compressor);
- if (ops->get_needed_memory)
- size += ops->get_needed_memory(max_block_size, compression_level);
- return size;
+ if (ops->get_needed_memory) {
+ size = ops->get_needed_memory(max_block_size, compression_level);
+
+ /* 0 is never valid and indicates an invalid max_block_size. */
+ if (size == 0)
+ return 0;
+ } else {
+ size = 0;
+ }
+ return size + sizeof(struct wimlib_compressor);
}
WIMLIBAPI int
{
struct wimlib_compressor *c;
+ if (!compressor_ctype_valid(ctype))
+ return WIMLIB_ERR_INVALID_COMPRESSION_TYPE;
+
if (c_ret == NULL)
return WIMLIB_ERR_INVALID_PARAM;
if (max_block_size == 0)
return WIMLIB_ERR_INVALID_PARAM;
- if (!compressor_ctype_valid(ctype))
- return WIMLIB_ERR_INVALID_COMPRESSION_TYPE;
-
c = MALLOC(sizeof(*c));
if (c == NULL)
return WIMLIB_ERR_NOMEM;
{
size_t compressed_size;
- wimlib_assert(uncompressed_size <= c->max_block_size);
+ if (unlikely(uncompressed_size == 0 || uncompressed_size > c->max_block_size))
+ return 0;
compressed_size = c->ops->compress(uncompressed_data,
uncompressed_size,