X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Fcompress.c;h=414fad0f1e7dece566a2938668d57d61041a4843;hb=9a20d1f99bd5dcd22e55300a5e29748486e585d7;hp=4c99dab145db7b04c5f6fb80f6207d6537b95179;hpb=27bb04887c1bee17ed06e24a71f3cfc9d51eb3a1;p=wimlib diff --git a/src/compress.c b/src/compress.c index 4c99dab1..414fad0f 100644 --- a/src/compress.c +++ b/src/compress.c @@ -8,20 +8,18 @@ /* * 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 @@ -90,6 +88,9 @@ wimlib_get_compressor_needed_memory(enum wimlib_compression_type ctype, if (!compressor_ctype_valid(ctype)) return 0; + if (max_block_size == 0) + return 0; + ops = compressor_ops[ctype]; if (compression_level == 0) @@ -97,10 +98,16 @@ wimlib_get_compressor_needed_memory(enum wimlib_compression_type ctype, 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 @@ -111,15 +118,15 @@ wimlib_create_compressor(enum wimlib_compression_type ctype, { 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;