aboutsummaryrefslogtreecommitdiff
path: root/lib/sqfs/comp
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-02-25 09:34:02 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-02-27 01:05:42 +0100
commit73132aa1f2643c01e929de69f1d2f1b74708a525 (patch)
treeef0c63b5f4c72e91875db51befe85937341083c1 /lib/sqfs/comp
parent3c1a4c2548cbbae96f44469278b53046c8b48868 (diff)
Fix: strictly verify compressor settings in config initialization
Make sure the function throws an error if a given compressor ID or flag is not known. This way, libsquahfs supports *exactly* and *only* what the on-disk format specifies. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs/comp')
-rw-r--r--lib/sqfs/comp/compressor.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/sqfs/comp/compressor.c b/lib/sqfs/comp/compressor.c
index 8049ade..0b4bf25 100644
--- a/lib/sqfs/comp/compressor.c
+++ b/lib/sqfs/comp/compressor.c
@@ -146,14 +146,13 @@ int sqfs_compressor_config_init(sqfs_compressor_config_t *cfg,
E_SQFS_COMPRESSOR id,
size_t block_size, sqfs_u16 flags)
{
- memset(cfg, 0, sizeof(*cfg));
+ sqfs_u32 flag_mask = SQFS_COMP_FLAG_GENERIC_ALL;
- cfg->id = id;
- cfg->flags = flags;
- cfg->block_size = block_size;
+ memset(cfg, 0, sizeof(*cfg));
switch (id) {
case SQFS_COMP_GZIP:
+ flag_mask |= SQFS_COMP_FLAG_GZIP_ALL;
cfg->opt.gzip.level = SQFS_GZIP_DEFAULT_LEVEL;
cfg->opt.gzip.window_size = SQFS_GZIP_DEFAULT_WINDOW;
break;
@@ -165,11 +164,25 @@ int sqfs_compressor_config_init(sqfs_compressor_config_t *cfg,
cfg->opt.zstd.level = SQFS_ZSTD_DEFAULT_LEVEL;
break;
case SQFS_COMP_XZ:
+ flag_mask |= SQFS_COMP_FLAG_XZ_ALL;
cfg->opt.xz.dict_size = block_size;
break;
- default:
+ case SQFS_COMP_LZMA:
+ break;
+ case SQFS_COMP_LZ4:
+ flag_mask |= SQFS_COMP_FLAG_LZ4_ALL;
break;
+ default:
+ return SQFS_ERROR_UNSUPPORTED;
+ }
+
+ if (flags & ~flag_mask) {
+ memset(cfg, 0, sizeof(*cfg));
+ return SQFS_ERROR_UNSUPPORTED;
}
+ cfg->id = id;
+ cfg->flags = flags;
+ cfg->block_size = block_size;
return 0;
}