dovecot-1.2: bzip plugin: Seeking streams backwards was broken.

dovecot at dovecot.org dovecot at dovecot.org
Wed Aug 27 19:21:35 EEST 2008


details:   http://hg.dovecot.org/dovecot-1.2/rev/74153b8e63a6
changeset: 8114:74153b8e63a6
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Aug 27 19:21:12 2008 +0300
description:
bzip plugin: Seeking streams backwards was broken.

diffstat:

1 file changed, 12 insertions(+)
src/plugins/zlib/istream-zlib.c |   12 ++++++++++++

diffs (30 lines):

diff -r 2d3e942a4cde -r 74153b8e63a6 src/plugins/zlib/istream-zlib.c
--- a/src/plugins/zlib/istream-zlib.c	Wed Aug 27 12:10:21 2008 +0300
+++ b/src/plugins/zlib/istream-zlib.c	Wed Aug 27 19:21:12 2008 +0300
@@ -18,6 +18,8 @@
 /* Default maximum buffer size. Seeking backwards is very expensive, so keep
    this pretty large */
 #define DEFAULT_MAX_BUFFER_SIZE (1024*1024)
+
+#include <unistd.h>
 
 struct zlib_istream {
 	struct istream_private istream;
@@ -124,7 +126,17 @@ i_stream_zlib_seek(struct istream_privat
 
 #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


More information about the dovecot-cvs mailing list