summaryrefslogtreecommitdiff
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
parent0f23f0396aede08a5d0c95d75b272f1b1787a365 (diff)
Strictly enfore min/max dictionary size in XZ & LZMA compressors
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--include/sqfs/compressor.h6
-rw-r--r--lib/sqfs/comp/compressor.c6
-rw-r--r--lib/sqfs/comp/lzma.c9
-rw-r--r--lib/sqfs/comp/xz.c6
-rw-r--r--tests/corpus/cantrbry.sha5128
5 files changed, 28 insertions, 7 deletions
diff --git a/include/sqfs/compressor.h b/include/sqfs/compressor.h
index c8cab02..7e687f6 100644
--- a/include/sqfs/compressor.h
+++ b/include/sqfs/compressor.h
@@ -410,6 +410,12 @@ typedef enum {
#define SQFS_LZMA_MAX_PB 4
#define SQFS_LZMA_DEFAULT_PB 2
+#define SQFS_LZMA_MIN_DICT_SIZE SQFS_META_BLOCK_SIZE
+#define SQFS_LZMA_MAX_DICT_SIZE SQFS_MAX_BLOCK_SIZE
+
+#define SQFS_XZ_MIN_DICT_SIZE SQFS_META_BLOCK_SIZE
+#define SQFS_XZ_MAX_DICT_SIZE SQFS_MAX_BLOCK_SIZE
+
#ifdef __cplusplus
extern "C" {
#endif
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)
diff --git a/tests/corpus/cantrbry.sha512 b/tests/corpus/cantrbry.sha512
index 6392967..864daf9 100644
--- a/tests/corpus/cantrbry.sha512
+++ b/tests/corpus/cantrbry.sha512
@@ -44,8 +44,8 @@ c62050026ec08b81d5736df6b2e9c289c7e23076933145c20a1411306325f9377845249767cd875c
5de2923d06eb750f7c16db79341509a2c98d445c47b3fe0c85d53f49524a03761fbf6275f7d865d9d595af0e8bd49699c5f86275fe095a338be003e6ddd22d7f cantrbry_lzma_256k_1_T.sqfs
c091c27f4fec31efd496b008e1d108f8dd814db04c7da01279e42c43d10a88525a79c8606353ad9ba815666e82d2f2d35d6e57532aaa09c6653749c804bd70d5 cantrbry_lzma_32k_1.sqfs
b38361d944d271c96a2bf0fad7b6c0d32e921e97d4124ed370e1ad2f1429f1dc62548053245bfd4b8ad18a5915835c26bc6b34a1ebf3363e5855e4a1d658037b cantrbry_lzma_32k_1_T.sqfs
-62eb0ce705ce1a8e8db1f261ebe85fc501ac25973ba95ea5f8028951b4932269f05d0d4a7fa9204710726cc62956e6a8e59cccccb9d2d5781453e1ee836bc623 cantrbry_lzma_4k_1.sqfs
-9d3394a27d5bcadf2ed75a403d6ceb0271caf8cb2fb04de0b7f02f12d5ba4a0c9d28dad070927b94fc3ce9badf8e13e43422c6602dc7d4ef966dc729b78538f3 cantrbry_lzma_4k_1_T.sqfs
+3eae1688316a54b3def2531fbc8e941874d696dc64ba0c5cf3c63757957dc758443d31202e4a2d520f96da2683d969ef64e06dda75ba8f17948da8488e0974d6 cantrbry_lzma_4k_1.sqfs
+842e62d0bef9ab2f44e4ab5e942b9e2d4c672e8ed8fca1fe3d3a4fd3380a2ad509ea25bc3e2c6a2cffd5e078bce567466df8aefbbdba0614f9ab5cd829de7aaf cantrbry_lzma_4k_1_T.sqfs
efa7995a3f3b8bf0530cd3f77972826c632b903ddda0380ad1271a9ad9eca01480e05736b1e1aaced5eddd95d225915e382b2cae4d691536d86771c7ac2a5121 cantrbry_lzma_512k_1.sqfs
58cb833df692494be6a455514318c8d64ba64fb2e5620a6a07f6d05bec2aca94a569cb3f09cf27264dadd0c65ba47fc1f4eef939b268182558b0f9ed5e32e69b cantrbry_lzma_512k_1_T.sqfs
abf898ffd7d26e404b107c1ee81ea6ff11700276c64ba4ed9ff59345e4bf9aac12f05fb406093f0532f7d8a2d791227e0d09b4e3b382269e6cb9de9f00e1c3a0 cantrbry_lzma_64k_1.sqfs
@@ -80,8 +80,8 @@ a95b495959a5eb3501f48f2ede31a8d9e86d13cf022f7da08206220c304ec26c37153c5ae748b572
5441aafb2e42dd4615e59563ef6acd0d20da4a9b92c2626a8cd6244fc0c8bca5fbba44e53a7a3dec9a1424855ded654b4e6dc963c31daf948f365f703a893bfb cantrbry_xz_256k_1_T.sqfs
8a312f0dae6ab75965d5de6603a3ab06f7a62878dbdc03f904d18b8bc58190532f1a14fe5f4b17af9e395e23846048fc5f509ea7ebc42e975a536aab85417ad3 cantrbry_xz_32k_1.sqfs
67f2c06e5a4802b1be12fb610f61e4ba26733054463ff7715e3b6fa6e9fa13e6901bccd54f3cb7741446533f76bb0aaf7fe7d6260db6e65d19df10b0c98fb3e2 cantrbry_xz_32k_1_T.sqfs
-5bd57a19185416dc6fac68afd83468e72b082058643f67aabad3bba058027a7e110cd1cd6bbd32d123f963d042130fee39a1e44bf45c6d8a3328ce2ae9c81cc4 cantrbry_xz_4k_1.sqfs
-50335092cc325ff8b47353c40283fc5f4c46311ad04789552fd971a8bc266e79b55cb44045d9378a40e37af96a830d816105503f665affcb1be83fa601635c0c cantrbry_xz_4k_1_T.sqfs
+3bc0873db21e7de4420227ffb4ed072ece0de1f81152a0adb67e734836e4479777016073e9c7fb8df190b6725dcb8436585d931bf68e46aa690125e9e82c9a86 cantrbry_xz_4k_1.sqfs
+6f51ce2ef88de2bb63fee6258547caaa34b5e72eadf1f2ada12efb46a912123c4735fdc2b568817ea6665c91db2f5b9ae3d487c6143cfa201d166a5c4717842d cantrbry_xz_4k_1_T.sqfs
9896f9ee2d822e9b5f726a27cab1cae9e32fd9cc4d3eced00998dd34c53191b584bc3cdddb4e3e9aacadabdff2a43d9762ff2a438c4f85a78fb17df8c1f7f171 cantrbry_xz_512k_1.sqfs
2b52cac2474d36ea0386040c32e5dba71f7bb3e17e75e137d9914af7ce7a2e9d5bffe57dd8c857c74bc186d75b5e590f0be61f0947d4457b3b4e45484f9b5fda cantrbry_xz_512k_1_T.sqfs
c56a091c10941302579793f1285c1a364eb1d7e1efa47957a662923cde51fb7dff2ec8f4e7c61901033f8901680c946f55aa95729a400556d1d5176b73dcd413 cantrbry_xz_64k_1.sqfs