From 30597cc7c5d566f671c84c025de97cb1fc2d242e Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Thu, 4 Jun 2020 05:32:47 +0200 Subject: Strictly enfore min/max dictionary size in XZ & LZMA compressors Signed-off-by: David Oberhollenzer --- lib/sqfs/comp/compressor.c | 6 ++++++ lib/sqfs/comp/lzma.c | 9 ++++++--- lib/sqfs/comp/xz.c | 6 ++++++ 3 files changed, 18 insertions(+), 3 deletions(-) (limited to 'lib/sqfs/comp') diff --git a/lib/sqfs/comp/compressor.c b/lib/sqfs/comp/compressor.c index 521471d..ff7ce0c 100644 --- a/lib/sqfs/comp/compressor.c +++ b/lib/sqfs/comp/compressor.c @@ -173,6 +173,9 @@ int sqfs_compressor_config_init(sqfs_compressor_config_t *cfg, cfg->opt.xz.lc = SQFS_XZ_DEFAULT_LC; cfg->opt.xz.lp = SQFS_XZ_DEFAULT_LP; cfg->opt.xz.pb = SQFS_XZ_DEFAULT_PB; + + if (block_size < SQFS_XZ_MIN_DICT_SIZE) + cfg->opt.xz.dict_size = SQFS_XZ_MIN_DICT_SIZE; break; case SQFS_COMP_LZMA: flag_mask |= SQFS_COMP_FLAG_LZMA_ALL; @@ -181,6 +184,9 @@ int sqfs_compressor_config_init(sqfs_compressor_config_t *cfg, cfg->opt.lzma.lc = SQFS_LZMA_DEFAULT_LC; cfg->opt.lzma.lp = SQFS_LZMA_DEFAULT_LP; cfg->opt.lzma.pb = SQFS_LZMA_DEFAULT_PB; + + if (block_size < SQFS_LZMA_MIN_DICT_SIZE) + cfg->opt.lzma.dict_size = SQFS_LZMA_MIN_DICT_SIZE; break; case SQFS_COMP_LZ4: flag_mask |= SQFS_COMP_FLAG_LZ4_ALL; diff --git a/lib/sqfs/comp/lzma.c b/lib/sqfs/comp/lzma.c index 59871b1..b674af9 100644 --- a/lib/sqfs/comp/lzma.c +++ b/lib/sqfs/comp/lzma.c @@ -238,6 +238,12 @@ int lzma_compressor_create(const sqfs_compressor_config_t *cfg, if (cfg->opt.lzma.dict_size == 0) return SQFS_ERROR_UNSUPPORTED; + if (cfg->opt.lzma.dict_size < SQFS_LZMA_MIN_DICT_SIZE) + return SQFS_ERROR_UNSUPPORTED; + + if (cfg->opt.lzma.dict_size > SQFS_LZMA_MAX_DICT_SIZE) + return SQFS_ERROR_UNSUPPORTED; + mask = cfg->opt.lzma.dict_size; mask &= mask - 1; @@ -262,9 +268,6 @@ int lzma_compressor_create(const sqfs_compressor_config_t *cfg, lzma->lp = cfg->opt.lzma.lp; lzma->pb = cfg->opt.lzma.pb; - if (lzma->dict_size < SQFS_META_BLOCK_SIZE) - lzma->dict_size = SQFS_META_BLOCK_SIZE; - base->get_configuration = lzma_get_configuration; base->do_block = (cfg->flags & SQFS_COMP_FLAG_UNCOMPRESS) ? lzma_uncomp_block : lzma_comp_block; diff --git a/lib/sqfs/comp/xz.c b/lib/sqfs/comp/xz.c index 20e6445..662a49f 100644 --- a/lib/sqfs/comp/xz.c +++ b/lib/sqfs/comp/xz.c @@ -291,6 +291,12 @@ int xz_compressor_create(const sqfs_compressor_config_t *cfg, if (cfg->opt.xz.level > SQFS_XZ_MAX_LEVEL) return SQFS_ERROR_UNSUPPORTED; + if (cfg->opt.xz.dict_size < SQFS_XZ_MIN_DICT_SIZE) + return SQFS_ERROR_UNSUPPORTED; + + if (cfg->opt.xz.dict_size > SQFS_XZ_MAX_DICT_SIZE) + return SQFS_ERROR_UNSUPPORTED; + xz = calloc(1, sizeof(*xz)); base = (sqfs_compressor_t *)xz; if (xz == NULL) -- cgit v1.2.3