From: Timo Sirainen Date: Thu, 2 Jul 2015 09:06:04 +0000 (+0200) Subject: mdbox: Make sure rebuilding doesn't try to add a copy of the message too many times. X-Git-Tag: 2.2.19.rc1~295 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c5c244da999da01465faea813031c96f96ff1c9f;p=thirdparty%2Fdovecot%2Fcore.git mdbox: Make sure rebuilding doesn't try to add a copy of the message too many times. Currently it just silently overflowed the 16bit refcount, which caused problems later. --- diff --git a/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c b/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c index 43090ca05c..3ccc15b956 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c +++ b/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c @@ -20,6 +20,8 @@ #include #include +#define REBUILD_MAX_REFCOUNT 32768 + struct mdbox_rebuild_msg { struct mdbox_rebuild_msg *guid_hash_next; @@ -458,7 +460,8 @@ rebuild_mailbox_multi(struct mdbox_storage_rebuild_context *ctx, GUID exists multiple times */ } - if (rec != NULL) T_BEGIN { + if (rec != NULL && + rec->refcount < REBUILD_MAX_REFCOUNT) T_BEGIN { /* keep this message. add it to mailbox index. */ i_assert(map_uid != 0); rec->refcount++; @@ -758,6 +761,7 @@ static int rebuild_restore_msg(struct mdbox_storage_rebuild_context *ctx, mail_index_update_ext(ctx->prev_msg.trans, seq, mbox->guid_ext_id, msg->guid_128, NULL); + i_assert(msg->refcount == 0); msg->refcount++; return 0; }