From db7aea1e9b05678faa04e83b3bb1586e1f6ddad2 Mon Sep 17 00:00:00 2001
From: David Goulet <dgoulet@riseup.net>
Date: Thu, 12 Jul 2018 17:44:01 -0400
Subject: [PATCH] istream: Request the minimal HEADER_SIZE and not MAGIC_SIZE

When looking at the header in an istream source, request from the parent
the HEADER_SIZE which contains the magic value and the version.

Else, it is possible to only have the MAGIC_SIZE and thus failing to
read the version.

This has been observed on Riseup email infrastructure leading to a
Permission denied to open the mbox because of the unknown version:

Error: [trees] Unknown version 0. Supporting 1 to 1

Signed-off-by: David Goulet <dgoulet@riseup.net>
---
 src/trees-istream.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/trees-istream.c b/src/trees-istream.c
index e94be7d..343091d 100644
--- a/src/trees-istream.c
+++ b/src/trees-istream.c
@@ -138,7 +138,7 @@ trees_istream_read_detect(struct trees_istream *sstream)
   i_stream_set_max_buffer_size(sstream->istream.parent,
                                MAX_ISTREAM_BUFFER_SIZE);
 
-  result = trees_istream_read_parent(sstream, MAGIC_SIZE, 0);
+  result = trees_istream_read_parent(sstream, HEADER_SIZE, 0);
   if (result <= 0) {
     /* Make sure we return an error here. */
     result = -1;
-- 
GitLab