From: Timo Sirainen Date: Wed, 27 Aug 2008 16:21:12 +0000 (+0300) Subject: bzip plugin: Seeking streams backwards was broken. X-Git-Tag: 1.2.alpha1~47 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=db0aaaddb037d21f24417d14bf49407a1cda53d8;p=thirdparty%2Fdovecot%2Fcore.git bzip plugin: Seeking streams backwards was broken. --HG-- branch : HEAD --- 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