diff src/lib-storage/index/mbox/mbox-sync-rewrite.c @ 2955:d5ee1bbd15f0 HEAD

Fixed mbox corruption in certain situations. Added more asserts to catch similiar problems if there still happens to be any.
author Timo Sirainen <tss@iki.fi>
date Tue, 07 Dec 2004 22:26:00 +0200
parents d1bae4aa3f80
children 8ef9f3d640e0
line wrap: on
line diff
--- a/src/lib-storage/index/mbox/mbox-sync-rewrite.c	Tue Dec 07 05:59:20 2004 +0200
+++ b/src/lib-storage/index/mbox/mbox-sync-rewrite.c	Tue Dec 07 22:26:00 2004 +0200
@@ -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;