changeset 15020:74037ec725d3 default tip

dbox: Fixed potential infinite looping when scanning a broken dbox file.
author Timo Sirainen <tss@iki.fi>
date Fri, 13 Jun 2014 11:21:07 +0300
parents d50ac1b3330d
children
files src/lib-storage/index/dbox-common/dbox-file-fix.c
diffstat 1 files changed, 3 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/dbox-common/dbox-file-fix.c	Thu Jun 12 23:51:28 2014 +0300
+++ b/src/lib-storage/index/dbox-common/dbox-file-fix.c	Fri Jun 13 11:21:07 2014 +0300
@@ -21,14 +21,16 @@
 	const unsigned char *data;
 	size_t size;
 	uoff_t offset = input->v_offset;
+	bool have_lf = FALSE;
 
 	data = i_stream_get_data(input, &size);
 	if (data[0] == '\n') {
 		data++; size--; offset++;
+		have_lf = TRUE;
 	}
 	i_assert(data[0] == DBOX_MAGIC_PRE[0]);
 	if (size < sizeof(*hdr)) {
-		*need_bytes = sizeof(*hdr);
+		*need_bytes = sizeof(*hdr) + (have_lf ? 1 : 0);
 		return -1;
 	}
 	hdr = (const void *)data;