dovecot-2.2: lib-index: Automatically grow header size on header...

dovecot at dovecot.org dovecot at dovecot.org
Mon Oct 13 15:51:27 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/931ab6f3357b
changeset: 17945:931ab6f3357b
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Oct 13 08:50:44 2014 -0700
description:
lib-index: Automatically grow header size on header updates.
This fixes assert-crashes when it didn't happen.

For example an old Maildir index could have had a header size 24. Dovecot
crashed then when trying to update it, because the new header size is 36 and
there wasn't an explicit mail_index_ext_resize_hdr() call.

diffstat:

 src/lib-index/mail-index-transaction-export.c |  24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)

diffs (41 lines):

diff -r ca6f330781e6 -r 931ab6f3357b src/lib-index/mail-index-transaction-export.c
--- a/src/lib-index/mail-index-transaction-export.c	Mon Oct 13 06:55:15 2014 -0700
+++ b/src/lib-index/mail-index-transaction-export.c	Mon Oct 13 08:50:44 2014 -0700
@@ -81,6 +81,18 @@
 	return buf;
 }
 
+static unsigned int
+ext_hdr_update_get_size(const struct mail_index_transaction_ext_hdr_update *hu)
+{
+	unsigned int i;
+
+	for (i = hu->alloc_size; i > 0; i--) {
+		if (hu->mask[i-1] != 0)
+			return i;
+	}
+	return 0;
+}
+
 static void log_append_ext_intro(struct mail_index_export_context *ctx,
 				 uint32_t ext_id, uint32_t reset_id,
 				 unsigned int *hdr_size_r)
@@ -139,6 +151,18 @@
 			intro->name_size = 0;
 		}
 		intro->flags = MAIL_TRANSACTION_EXT_INTRO_FLAG_NO_SHRINK;
+
+		/* handle increasing header size automatically */
+		if (array_is_created(&t->ext_hdr_updates) &&
+		    ext_id < array_count(&t->ext_hdr_updates)) {
+			const struct mail_index_transaction_ext_hdr_update *hu;
+			unsigned int hdr_update_size;
+
+			hu = array_idx(&t->ext_hdr_updates, ext_id);
+			hdr_update_size = ext_hdr_update_get_size(hu);
+			if (intro->hdr_size < hdr_update_size)
+				intro->hdr_size = hdr_update_size;
+		}
 	}
 	if (reset_id != 0) {
 		/* we're going to reset this extension in this transaction */


More information about the dovecot-cvs mailing list