We were truncating to the size of the mmaped area rather than the
length of the file, causing blocks of bogus zero bytes in the
resulting cache file after an aborted append.

===================================================================
---
 imap/append.c |    6 ++++--
 imap/append.h |    2 +-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/imap/append.c b/imap/append.c
index cb4025b..8f06896 100644
--- a/imap/append.c
+++ b/imap/append.c
@@ -234,8 +234,10 @@ int append_setup(struct appendstate *as, const char *name,
        as->userid[0] = '\0';
     }
 
+    /* store original size to truncate if append is aborted */
+    as->orig_cache_size = as->m.cache_size;
+
     /* zero out metadata */
-    as->orig_cache_len = as->m.cache_len;
     as->nummsg = as->numanswered = 
        as->numdeleted = as->numflagged = 0;
     as->quota_used = 0;
@@ -369,7 +371,7 @@ int append_abort(struct appendstate *as)
     }
 
     /* truncate the cache */
-    ftruncate(as->m.cache_fd, as->orig_cache_len);
+    ftruncate(as->m.cache_fd, as->orig_cache_size);
 
     /* unlock mailbox */
     mailbox_unlock_index(&as->m);
diff --git a/imap/append.h b/imap/append.h
index 81d1cb6..ec726bb 100644
--- a/imap/append.h
+++ b/imap/append.h
@@ -76,7 +76,7 @@ struct appendstate {
                                /* current state of append */
 
     /* if we abort, where should we truncate the cache file? */
-    unsigned long orig_cache_len;
+    unsigned long orig_cache_size;
 
     int writeheader;           /* did we change the mailbox header? */
 
-- 
1.5.6.3

Reply via email to