]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Add mail_index_cache_optimization_settings.max_size
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 10 Feb 2020 15:44:29 +0000 (17:44 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 14 Feb 2020 08:42:53 +0000 (08:42 +0000)
This can be used to limit the cache file's maximum size.

src/lib-index/mail-cache-transaction.c
src/lib-index/mail-cache.c
src/lib-index/mail-index.c
src/lib-index/mail-index.h

index d09a47a9d244e233ee922306428b2afd5dff4e5f..0ff2545c4a94a234abd850cf2d6500e33d34d4dd 100644 (file)
@@ -436,7 +436,7 @@ mail_cache_transaction_flush(struct mail_cache_transaction_ctx *ctx)
                if (!ESTALE_FSTAT(errno))
                        mail_cache_set_syscall_error(ctx->cache, "fstat()");
                ret = -1;
-       } else if ((uint32_t)-1 < st.st_size + ctx->last_rec_pos) {
+       } else if (st.st_size + ctx->last_rec_pos > ctx->cache->index->optimization_set.cache.max_size) {
                mail_cache_set_corrupted(ctx->cache, "Cache file too large");
                ret = -1;
        } else {
index 8f4f2e57d0d58bb2c152697b14a0b9c07aeb0fa0..caa3d12563d2920e7724ea0fcd141675672f01b2 100644 (file)
@@ -796,13 +796,14 @@ int mail_cache_append(struct mail_cache *cache, const void *data, size_t size,
                                mail_cache_set_syscall_error(cache, "fstat()");
                        return -1;
                }
-               if (st.st_size > (uint32_t)-1) {
+               if ((uoff_t)st.st_size > cache->index->optimization_set.cache.max_size) {
                        mail_cache_set_corrupted(cache, "Cache file too large");
                        return -1;
                }
                *offset = st.st_size;
        }
-       if ((uint32_t)-1 - *offset < size) {
+       if (*offset >= cache->index->optimization_set.cache.max_size ||
+           cache->index->optimization_set.cache.max_size - *offset < size) {
                mail_cache_set_corrupted(cache, "Cache file too large");
                return -1;
        }
index 0daf8cf9ca3cb54e37f0be9b67efee6061c2af7a..8f342a40e1d0dd45d7d77bb40382f7f9dfc04178 100644 (file)
@@ -47,6 +47,7 @@ static const struct mail_index_optimization_settings default_optimization_set =
        .cache = {
                .unaccessed_field_drop_secs = 3600 * 24 * 30,
                .record_max_size = 64 * 1024,
+               .max_size = (uint32_t)-1,
                .compress_min_size = 32 * 1024,
                .compress_delete_percentage = 20,
                .compress_continued_percentage = 200,
@@ -210,6 +211,8 @@ void mail_index_set_optimization_settings(struct mail_index *index,
        if (set->cache.unaccessed_field_drop_secs != 0)
                dest->cache.unaccessed_field_drop_secs =
                        set->cache.unaccessed_field_drop_secs;
+       if (set->cache.max_size != 0)
+               dest->cache.max_size = set->cache.max_size;
        if (set->cache.compress_min_size != 0)
                dest->cache.compress_min_size = set->cache.compress_min_size;
        if (set->cache.compress_delete_percentage != 0)
index a54c41d9f6d952c932bb39178d253156e8943679..169e32f6b28daa390fb5ea36d401abc09b9ecd6b 100644 (file)
@@ -274,6 +274,8 @@ struct mail_index_cache_optimization_settings {
        /* If cache record becomes larger than this, don't add it. */
        unsigned int record_max_size;
 
+       /* Maximum size for the cache file. Internally the limit is 1 GB. */
+       uoff_t max_size;
        /* Never compress the file if it's smaller than this */
        uoff_t compress_min_size;
        /* Compress the file when n% of records are deleted */