summaryrefslogtreecommitdiff
path: root/lib/sqfs
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-06-04 05:32:47 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-06-04 05:38:40 +0200
commit30597cc7c5d566f671c84c025de97cb1fc2d242e (patch)
tree985410632a31d952fb3430c001ed5e7780cf0e0b /lib/sqfs
parent0f23f0396aede08a5d0c95d75b272f1b1787a365 (diff)
Strictly enfore min/max dictionary size in XZ & LZMA compressors
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs')
-rw-r--r--lib/sqfs/comp/compressor.c6
-rw-r--r--lib/sqfs/comp/lzma.c9
-rw-r--r--lib/sqfs/comp/xz.c6
3 files changed, 18 insertions, 3 deletions
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)