diff options
author | Lasse Collin <lasse.collin@tukaani.org> | 2008-12-01 16:30:11 +0200 |
---|---|---|
committer | Lasse Collin <lasse.collin@tukaani.org> | 2008-12-01 16:30:11 +0200 |
commit | 656ec87882ee74b192c4ea4a233a235eca7b04d4 (patch) | |
tree | b0d2b9cc96ebedc03d2b8f88d452a84417b1933e /src/liblzma/delta/delta_common.c | |
parent | Automake includes the m4 directory, so don't add it in (diff) | |
download | xz-656ec87882ee74b192c4ea4a233a235eca7b04d4.tar.xz |
Added lzma_delta_coder_memusage() which also validates
the options.
Diffstat (limited to 'src/liblzma/delta/delta_common.c')
-rw-r--r-- | src/liblzma/delta/delta_common.c | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/src/liblzma/delta/delta_common.c b/src/liblzma/delta/delta_common.c index 90b5552b..ee2abd65 100644 --- a/src/liblzma/delta/delta_common.c +++ b/src/liblzma/delta/delta_common.c @@ -18,6 +18,7 @@ /////////////////////////////////////////////////////////////////////////////// #include "delta_common.h" +#include "delta_private.h" static void @@ -47,15 +48,14 @@ lzma_delta_coder_init(lzma_next_coder *next, lzma_allocator *allocator, // Coding function is different for encoder and decoder. next->code = code; - // Set the delta distance. - if (filters[0].options == NULL) - return LZMA_PROG_ERROR; - next->coder->distance - = ((lzma_options_delta *)(filters[0].options))->dist; - if (next->coder->distance < LZMA_DELTA_DIST_MIN - || next->coder->distance > LZMA_DELTA_DIST_MAX) + // Validate the options. + if (lzma_delta_coder_memusage(filters[0].options) == UINT64_MAX) return LZMA_OPTIONS_ERROR; + // Set the delta distance. + const lzma_options_delta *opt = filters[0].options; + next->coder->distance = opt->dist; + // Initialize the rest of the variables. next->coder->pos = 0; memzero(next->coder->history, LZMA_DELTA_DIST_MAX); @@ -64,3 +64,17 @@ lzma_delta_coder_init(lzma_next_coder *next, lzma_allocator *allocator, return lzma_next_filter_init(&next->coder->next, allocator, filters + 1); } + + +extern uint64_t +lzma_delta_coder_memusage(const void *options) +{ + const lzma_options_delta *opt = options; + + if (opt == NULL || opt->type != LZMA_DELTA_TYPE_BYTE + || opt->dist < LZMA_DELTA_DIST_MIN + || opt->dist > LZMA_DELTA_DIST_MAX) + return UINT64_MAX; + + return sizeof(lzma_coder); +} |