[dovecot-cvs] dovecot/src/lib-mail message-decoder.c,1.2,1.3
tss at dovecot.org
tss at dovecot.org
Sat Dec 9 21:53:15 UTC 2006
Update of /var/lib/cvs/dovecot/src/lib-mail
In directory talvi:/tmp/cvs-serv18585
Modified Files:
message-decoder.c
Log Message:
Fixes
Index: message-decoder.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-mail/message-decoder.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- message-decoder.c 24 Oct 2006 23:45:14 -0000 1.2
+++ message-decoder.c 9 Dec 2006 21:53:13 -0000 1.3
@@ -18,8 +18,8 @@
CONTENT_TYPE_BASE64
};
-/* Both base64 and q-p takes max 3 bytes per character */
-#define MAX_ENCODING_BUF_SIZE 2
+/* base64 takes max 4 bytes per character, q-p takes max 3. */
+#define MAX_ENCODING_BUF_SIZE 3
/* UTF-8 takes max 5 bytes per character. Not sure about others, but I'd think
10 is more than enough for everyone.. */
@@ -236,10 +236,10 @@
ctx->encoding_size + skip,
&pos, ctx->buf);
i_assert(pos > ctx->encoding_size);
- skip = (ctx->encoding_size + skip) - pos;
+ skip = pos - ctx->encoding_size;
}
- quoted_printable_decode(input->data, input->size,
+ quoted_printable_decode(input->data + skip, input->size - skip,
&pos, ctx->buf);
pos += skip;
data = ctx->buf->data;
@@ -255,7 +255,7 @@
return FALSE;
}
i_assert(pos > ctx->encoding_size);
- skip = (ctx->encoding_size + skip) - pos;
+ skip = pos - ctx->encoding_size;
}
if (base64_decode(input->data + skip, input->size - skip,
&pos, ctx->buf) < 0) {
@@ -263,6 +263,11 @@
the rest of it */
return FALSE;
}
+ if (pos < input->size - skip && pos > 0 &&
+ input->data[pos + skip - 1] == '=') {
+ /* end of base64 input */
+ pos = input->size - skip;
+ }
pos += skip;
data = ctx->buf->data;
size = ctx->buf->used;
@@ -271,6 +276,7 @@
if (pos != input->size) {
/* @UNSAFE */
+ i_assert(pos < input->size);
ctx->encoding_size = input->size - pos;
i_assert(ctx->encoding_size <= sizeof(ctx->encoding_buf));
memcpy(ctx->encoding_buf, input->data + pos,
@@ -312,6 +318,7 @@
i_free_and_null(ctx->content_charset);
ctx->content_type = CONTENT_TYPE_BINARY;
ctx->charset_utf8 = TRUE;
+ ctx->encoding_size = 0;
}
output->part = input->part;
More information about the dovecot-cvs
mailing list