From de3967312fb2f6c5cb217c3497ad7b4f56e46458 Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Mon, 26 Aug 2013 09:32:47 +0400 Subject: [PATCH] Fix recovering from possible decompression error. Since insert_from_gap doesn't always move point, we can't use PT as the position where the partially decompressed data ends, and should count how may bytes was produced so far. * decompress.c (struct decompress_unwind_data): Add nbytes member. (unwind_decompress): Really delete partially uncompressed data. (Fzlib_decompress_region): Take decompressed data size into account. --- src/ChangeLog | 10 ++++++++++ src/decompress.c | 7 ++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index f2bb1feb2c..e4dcfffa02 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2013-08-26 Dmitry Antipov + + Fix recovering from possible decompression error. Since + insert_from_gap doesn't always move point, we can't use PT as + the position where the partially decompressed data ends, and + should count how may bytes was produced so far. + * decompress.c (struct decompress_unwind_data): Add nbytes member. + (unwind_decompress): Really delete partially uncompressed data. + (Fzlib_decompress_region): Take decompressed data size into account. + 2013-08-26 Dmitry Antipov * syntax.c (init_syntax_once): Adjust comment and do an early diff --git a/src/decompress.c b/src/decompress.c index c49f39a8ba..dc9f4b72d9 100644 --- a/src/decompress.c +++ b/src/decompress.c @@ -85,7 +85,7 @@ init_zlib_functions (void) struct decompress_unwind_data { - ptrdiff_t old_point, start; + ptrdiff_t old_point, start, nbytes; z_stream *stream; }; @@ -97,7 +97,7 @@ unwind_decompress (void *ddata) /* Delete any uncompressed data already inserted on error. */ if (data->start) - del_range (data->start, PT); + del_range (data->start, data->start + data->nbytes); /* Put point where it was, or if the buffer has shrunk because the compressed data is bigger than the uncompressed, at @@ -173,7 +173,7 @@ This function can be called only in unibyte buffers. */) unwind_data.start = iend; unwind_data.stream = &stream; unwind_data.old_point = PT; - + unwind_data.nbytes = 0; record_unwind_protect_ptr (unwind_decompress, &unwind_data); /* Insert the decompressed data at the end of the compressed data. */ @@ -201,6 +201,7 @@ This function can be called only in unibyte buffers. */) pos_byte += avail_in - stream.avail_in; decompressed = avail_out - stream.avail_out; insert_from_gap (decompressed, decompressed, 0); + unwind_data.nbytes += decompressed; QUIT; } while (inflate_status == Z_OK); -- 2.20.1