[dovecot-cvs] dovecot/src/lib-storage/index/mbox mbox-sync-parse.c, 1.29, 1.30 mbox-sync-rewrite.c, 1.39, 1.40 mbox-sync.c, 1.125, 1.126

cras at dovecot.org cras at dovecot.org
Tue Dec 7 22:26:03 EET 2004


Update of /var/lib/cvs/dovecot/src/lib-storage/index/mbox
In directory talvi:/tmp/cvs-serv19222

Modified Files:
	mbox-sync-parse.c mbox-sync-rewrite.c mbox-sync.c 
Log Message:
Fixed mbox corruption in certain situations. Added more asserts to catch
similiar problems if there still happens to be any.



Index: mbox-sync-parse.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-parse.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- mbox-sync-parse.c	3 Oct 2004 16:32:59 -0000	1.29
+++ mbox-sync-parse.c	7 Dec 2004 20:26:00 -0000	1.30
@@ -58,6 +58,7 @@
 	}
 
 	if ((ssize_t)space > ctx->mail.space) {
+		i_assert(space != 0);
 		ctx->mail.offset = hdr->full_value_offset + i;
 		ctx->mail.space = space;
 	}

Index: mbox-sync-rewrite.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-rewrite.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- mbox-sync-rewrite.c	25 Oct 2004 21:55:15 -0000	1.39
+++ mbox-sync-rewrite.c	7 Dec 2004 20:26:00 -0000	1.40
@@ -118,8 +118,10 @@
 		ctx->header_first_change = pos;
 	ctx->header_last_change = (size_t)-1;
 
-	ctx->mail.offset = ctx->hdr_offset + start_pos;
 	ctx->mail.space = (pos - start_pos) + size;
+	ctx->mail.offset = ctx->hdr_offset;
+	if (ctx->mail.space > 0)
+		ctx->mail.offset += start_pos;
 }
 
 static void mbox_sync_header_remove_space(struct mbox_sync_mail_context *ctx,
@@ -174,7 +176,9 @@
 
 	if (ctx->mail.space < (off_t)(data_size - last_line_pos)) {
 		ctx->mail.space = data_size - last_line_pos;
-		ctx->mail.offset = ctx->hdr_offset + last_line_pos;
+		ctx->mail.offset = ctx->hdr_offset;
+		if (ctx->mail.space > 0)
+			ctx->mail.offset += last_line_pos;
 	}
 }
 
@@ -487,6 +491,7 @@
 		}
 
 		i_assert(move_diff >= 0 || idx == first_nonexpunged_idx);
+		i_assert(next_end_offset <= end_offset);
 
 		end_offset = next_end_offset;
 		mails[idx].from_offset += move_diff;

Index: mbox-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync.c,v
retrieving revision 1.125
retrieving revision 1.126
diff -u -d -r1.125 -r1.126
--- mbox-sync.c	28 Nov 2004 23:55:40 -0000	1.125
+++ mbox-sync.c	7 Dec 2004 20:26:00 -0000	1.126
@@ -609,6 +609,8 @@
 	uoff_t end_offset, move_diff, extra_space, needed_space;
 	uint32_t last_seq;
 
+	i_assert(mail_ctx->mail.uid == 0 || mail_ctx->mail.space > 0 ||
+		 mail_ctx->mail.offset == mail_ctx->hdr_offset);
 	buffer_append(sync_ctx->mails, &mail_ctx->mail, sizeof(mail_ctx->mail));
 
 	sync_ctx->space_diff += mail_ctx->mail.space;



More information about the dovecot-cvs mailing list