From 3e16d51dd645667b05ff826665b1fc353aa41cd9 Mon Sep 17 00:00:00 2001 From: Lasse Collin Date: Tue, 11 Dec 2007 16:49:19 +0200 Subject: Remove uncompressed size tracking from the filter encoders. It's not strictly needed there, and just complicates the code. LZ encoder never even had this feature. The primary reason to have uncompressed size tracking in filter encoders was validating that the application doesn't give different amount of input that it had promised. A side effect was to validate internal workings of liblzma. Uncompressed size tracking is still present in the Block encoder. Maybe it should be added to LZMA_Alone and raw encoders too. It's simpler to have one coder just to validate the uncompressed size instead of having it in every filter. --- src/liblzma/simple/simple_coder.c | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) (limited to 'src/liblzma/simple') diff --git a/src/liblzma/simple/simple_coder.c b/src/liblzma/simple/simple_coder.c index f60dff34..6ecd119e 100644 --- a/src/liblzma/simple/simple_coder.c +++ b/src/liblzma/simple/simple_coder.c @@ -39,44 +39,23 @@ copy_or_code(lzma_coder *coder, lzma_allocator *allocator, if (coder->next.code == NULL) { const size_t in_avail = in_size - *in_pos; - if (coder->is_encoder) { - if (action == LZMA_FINISH) { - // If uncompressed size is known and the - // amount of available input doesn't match - // the uncompressed size, return an error. - if (coder->uncompressed_size - != LZMA_VLI_VALUE_UNKNOWN - && coder->uncompressed_size - != in_avail) - return LZMA_DATA_ERROR; - - } else if (coder->uncompressed_size - < (lzma_vli)(in_avail)) { - // There is too much input available. - return LZMA_DATA_ERROR; - } - } else { + if (!coder->is_encoder) { // Limit in_size so that we don't copy too much. if ((lzma_vli)(in_avail) > coder->uncompressed_size) in_size = *in_pos + (size_t)( coder->uncompressed_size); } - // Store the old position so we can update uncompressed_size. const size_t out_start = *out_pos; - - // Copy the data bufcpy(in, in_pos, in_size, out, out_pos, out_size); - // Update uncompressed_size. - if (coder->uncompressed_size != LZMA_VLI_VALUE_UNKNOWN) - coder->uncompressed_size -= *out_pos - out_start; - // Check if end of stream was reached. if (coder->is_encoder) { if (action == LZMA_FINISH && *in_pos == in_size) coder->end_was_reached = true; - } else { + } else if (coder->uncompressed_size + != LZMA_VLI_VALUE_UNKNOWN) { + coder->uncompressed_size -= *out_pos - out_start; if (coder->uncompressed_size == 0) coder->end_was_reached = true; } -- cgit v1.2.3