]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Fix potential error when reading from uncommitted cache transaction
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 24 Oct 2016 10:28:44 +0000 (13:28 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 24 Oct 2016 11:26:19 +0000 (14:26 +0300)
If dovecot.index.cache is compressed during the transaction, the new cache
fields mapping doesn't necessarily match what is in the transaction.

Fixes:
Error: Corrupted index cache file .../dovecot.index.cache: field index too large (27 >= 17)

Although there may be other cache corruption errors it also fixes.

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

index bbd7e9bcb95190c2273ebd51a5ffc72c84fda5da..9e91b11b23ac1798cc5ac7e06e8182bca8ff2371 100644 (file)
@@ -289,6 +289,14 @@ mail_cache_transaction_lookup_rec(struct mail_cache_transaction_ctx *ctx,
        const struct mail_cache_transaction_rec *recs;
        unsigned int i, count;
 
+       if (MAIL_CACHE_IS_UNUSABLE(ctx->cache) ||
+           ctx->cache_file_seq != ctx->cache->hdr->file_seq) {
+               /* Cache was compressed during this transaction. We can't
+                  safely use the data anymore, since its fields won't match
+                  cache->file_fields_map. */
+               return NULL;
+       }
+
        recs = array_get(&ctx->cache_data_seq, &count);
        for (i = *trans_next_idx; i < count; i++) {
                if (recs[i].seq == seq) {