This can be used to limit the cache file's maximum size.
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 {
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;
}
.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,
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)
/* 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 */