From db0aaaddb037d21f24417d14bf49407a1cda53d8 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Wed, 27 Aug 2008 19:21:12 +0300 Subject: [PATCH] bzip plugin: Seeking streams backwards was broken. --HG-- branch : HEAD --- src/plugins/zlib/istream-zlib.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/plugins/zlib/istream-zlib.c b/src/plugins/zlib/istream-zlib.c index 5d7a6a4c16..4b5b6e8221 100644 --- a/src/plugins/zlib/istream-zlib.c +++ b/src/plugins/zlib/istream-zlib.c @@ -19,6 +19,8 @@ this pretty large */ #define DEFAULT_MAX_BUFFER_SIZE (1024*1024) +#include + struct zlib_istream { struct istream_private istream; @@ -124,7 +126,17 @@ i_stream_zlib_seek(struct istream_private *stream, uoff_t v_offset, bool mark) #ifndef HAVE_GZSEEK if (v_offset < start_offset) { + /* need to reopen, but since closing the file closes the + file descriptor we'll have to duplicate it first. */ + int fd = dup(zstream->fd); + if (fd == -1) { + stream->istream.stream_errno = errno; + i_error("zlib istream: dup() failed: %m"); + i_stream_close(&stream->istream); + return; + } gzclose(zstream->file); + zstream->fd = fd; zstream->file = gzdopen(zstream->fd, "r"); } #else -- 2.47.3