From 5bd1c1d4fe3265d5e6b6054044fd6d78e42c9d0a Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Thu, 3 Mar 2016 00:15:30 +0200 Subject: [PATCH] lib-index: After MAIL_INDEX_OPEN_FLAG_SAVEONLY access cache's read_buf wasn't always reset. This could have caused at least errors like: Corrupted index cache file .../dovecot.index.cache: File too small I'm not sure if it might have also returned stale data sometimes. Easy way to reproduce this bug was: imaptest copy=100 copybox=Trash & imaptest box=Trash append=0 --- src/lib-index/mail-cache.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib-index/mail-cache.c b/src/lib-index/mail-cache.c index 4f6e43fd68..34c05c5d84 100644 --- a/src/lib-index/mail-cache.c +++ b/src/lib-index/mail-cache.c @@ -60,6 +60,8 @@ void mail_cache_file_close(struct mail_cache *cache) if (cache->file_cache != NULL) file_cache_set_fd(cache->file_cache, -1); + if (cache->read_buf != NULL) + buffer_set_used_size(cache->read_buf, 0); cache->mmap_base = NULL; cache->hdr = NULL; @@ -465,6 +467,8 @@ int mail_cache_map(struct mail_cache *cache, size_t offset, size_t size, /* map the whole file */ cache->hdr = NULL; cache->mmap_length = 0; + if (cache->read_buf != NULL) + buffer_set_used_size(cache->read_buf, 0); cache->mmap_base = mmap_ro_file(cache->fd, &cache->mmap_length); if (cache->mmap_base == MAP_FAILED) {