]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
Make the memusage functions of LZMA1 and LZMA2 decoders
authorLasse Collin <lasse.collin@tukaani.org>
Mon, 1 Dec 2008 20:58:22 +0000 (22:58 +0200)
committerLasse Collin <lasse.collin@tukaani.org>
Mon, 1 Dec 2008 20:58:22 +0000 (22:58 +0200)
to validate the filter options.

src/liblzma/lzma/lzma2_decoder.c
src/liblzma/lzma/lzma_decoder.c
src/liblzma/lzma/lzma_decoder.h

index 7f1f45f426de00c76c113ea531918548033f6829..4470b4b1659489d37f7585cf758d7c1b4545fbe4 100644 (file)
@@ -261,11 +261,8 @@ lzma_lzma2_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
 extern uint64_t
 lzma_lzma2_decoder_memusage(const void *options)
 {
-       const uint64_t lzma_memusage = lzma_lzma_decoder_memusage(options);
-       if (lzma_memusage == UINT64_MAX)
-               return UINT64_MAX;
-
-       return sizeof(lzma_coder) + lzma_memusage;
+       return sizeof(lzma_coder)
+                       + lzma_lzma_decoder_memusage_nocheck(options);
 }
 
 
index df3371e2efa36c4d9150c8f99184a4c7d497f2ea..03e3251a9fa47b622384e250762fbe186f7715aa 100644 (file)
@@ -1012,14 +1012,20 @@ lzma_lzma_lclppb_decode(lzma_options_lzma *options, uint8_t byte)
 
 
 extern uint64_t
-lzma_lzma_decoder_memusage(const void *options)
+lzma_lzma_decoder_memusage_nocheck(const void *options)
 {
        const lzma_options_lzma *const opt = options;
-       const uint64_t lz_memusage = lzma_lz_decoder_memusage(opt->dict_size);
-       if (lz_memusage == UINT64_MAX)
+       return sizeof(lzma_coder) + lzma_lz_decoder_memusage(opt->dict_size);
+}
+
+
+extern uint64_t
+lzma_lzma_decoder_memusage(const void *options)
+{
+       if (!is_lclppb_valid(options))
                return UINT64_MAX;
 
-       return sizeof(lzma_coder) + lz_memusage;
+       return lzma_lzma_decoder_memusage_nocheck(options);
 }
 
 
index 3792f452745e62a4b47bdb7131c5fc71428f7577..133d260835ce056f34cde7cd7f2d254ece8fbbba 100644 (file)
@@ -49,6 +49,11 @@ extern bool lzma_lzma_lclppb_decode(
 extern lzma_ret lzma_lzma_decoder_create(
                lzma_lz_decoder *lz, lzma_allocator *allocator,
                const void *opt, size_t *dict_size);
+
+/// Gets memory usage without validating lc/lp/pb. This is used by LZMA2
+/// decoder, because raw LZMA2 decoding doesn't need lc/lp/pb.
+extern uint64_t lzma_lzma_decoder_memusage_nocheck(const void *options);
+
 #endif
 
 #endif