From b99b56515e12c3f8bbc1ee2a67a5c558d4a4c9eb Mon Sep 17 00:00:00 2001 From: "bienvenu%nventure.com" Date: Fri, 1 Dec 2006 19:26:30 +0000 Subject: [PATCH] fix 362512 issues with rfc2047 encoding, sr=mscott git-svn-id: svn://10.0.0.236/branches/MOZILLA_1_8_BRANCH@216275 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/mailnews/mime/src/comi18n.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mozilla/mailnews/mime/src/comi18n.cpp b/mozilla/mailnews/mime/src/comi18n.cpp index 2b521037a1f..b3c21652b0f 100644 --- a/mozilla/mailnews/mime/src/comi18n.cpp +++ b/mozilla/mailnews/mime/src/comi18n.cpp @@ -594,13 +594,19 @@ char * apply_rfc2047_encoding(const char *_src, PRBool structured, const char *c if (!_src) return nsnull; - if ((src = src_head = nsCRT::strdup(_src)) == nsnull) + + //=???...?= + PRInt32 perLineOverhead = strlen(charset) + 10; + + if (perLineOverhead > foldlen || (src = src_head = nsCRT::strdup(_src)) == nsnull) return nsnull; /* allocate enough buffer for conversion, this way it can avoid do another memory allocation which is expensive */ - outputlen = strlen(src) * 4 + kMAX_CSNAME + 8; + PRInt32 charsPerLine = (foldlen - perLineOverhead) / 4; + PRInt32 maxNumLines = (strlen(src) / charsPerLine) + 1; + outputlen = strlen(src) * 4 + (maxNumLines * perLineOverhead) + 20 /* fudge */; if ((outputtail = output = (char *)PR_Malloc(outputlen)) == nsnull) { PR_Free(src_head); return nsnull;