# HG changeset patch # User Timo Sirainen # Date 1202925641 -7200 # Node ID 40b6d4113e526bb6b39c29cc60a50d64cf2bd2ad # Parent b8b100c7771c1e20a9a89fd4e5545ab33cdb449f Log an error if uid_validity field is updated unexpectedly. If next_uid field decreases log an error and ignore the update. diff -r b8b100c7771c -r 40b6d4113e52 src/lib-index/mail-index-sync-update.c --- a/src/lib-index/mail-index-sync-update.c Wed Feb 13 18:06:03 2008 +0200 +++ b/src/lib-index/mail-index-sync-update.c Wed Feb 13 20:00:41 2008 +0200 @@ -385,6 +385,8 @@ { struct mail_index_map *map = ctx->view->map; uint32_t orig_log_file_tail_offset = map->hdr.log_file_tail_offset; + uint32_t orig_next_uid = map->hdr.next_uid; + uint32_t orig_uid_validity = map->hdr.uid_validity; if (u->offset >= map->hdr.base_header_size || u->offset + u->size > map->hdr.base_header_size) { @@ -407,6 +409,28 @@ u + 1, sizeof(map->hdr) - u->offset); } + /* UIDVALIDITY can be changed only by resetting the index */ +#define MAIL_INDEX_HEADER_UPDATE_FIELD_IN_RANGE(u, field) \ + ((u)->offset <= offsetof(struct mail_index_header, field) && \ + (u)->offset + (u)->size > offsetof(struct mail_index_header, field)) + + + if (orig_uid_validity != 0 && + MAIL_INDEX_HEADER_UPDATE_FIELD_IN_RANGE(u, uid_validity)) { + mail_index_sync_set_corrupted(ctx, + "uid_validity updated unexpectedly: %u -> %u", + orig_uid_validity, map->hdr.uid_validity); + /* let it through anyway, although this could give wrong + "next_uid shrank" errors if the value actually changed.. */ + } + if (map->hdr.next_uid < orig_next_uid) { + mail_index_sync_set_corrupted(ctx, + "next_uid shrank ignored: %u -> %u", + orig_next_uid, map->hdr.next_uid); + map->hdr.next_uid = orig_next_uid; + return -1; + } + /* the tail offset updates are intended for internal transaction log handling. we'll update the offset in the header only when the sync is finished. */