fix bug 593829, a=standard8, crash in nsBufferedOutputStream::Write
authorDavid Bienvenu <bienvenu@nventure.com>
Tue, 09 Aug 2011 11:42:18 -0700
changeset 8334 c9f70dd77f6576eef38b4959834d230b7ba12683
parent 8333 52f5f813485abd4e641b035b69e2bc9b88c5798f
child 8335 7ef5c796fa98bb6e21403b53b4266729c38028e3
push idunknown
push userunknown
push dateunknown
reviewersstandard8, crash
bugs593829
fix bug 593829, a=standard8, crash in nsBufferedOutputStream::Write
mailnews/base/util/nsMsgMailNewsUrl.cpp
--- a/mailnews/base/util/nsMsgMailNewsUrl.cpp
+++ b/mailnews/base/util/nsMsgMailNewsUrl.cpp
@@ -881,36 +881,37 @@ NS_IMETHODIMP nsMsgSaveAsListener::OnDat
                           maxReadCount,
                           &readCount);
       if (NS_FAILED(rv)) return rv;
 
       m_leftOver += readCount;
       m_dataBuffer[m_leftOver] = '\0';
 
       start = m_dataBuffer;
+      // make sure we don't insert another LF, accidentally, by ignoring
+      // second half of CRLF spanning blocks.
+      if (lastCharInPrevBuf == '\r' && *start == '\n')
+        start++;
+
       end = PL_strchr(start, '\r');
       if (!end)
           end = PL_strchr(start, '\n');
       else if (*(end+1) == '\n' && linebreak_len == 0)
           linebreak_len = 2;
 
       if (linebreak_len == 0) // not initialize yet
           linebreak_len = 1;
 
       count -= readCount;
       maxReadCount = SAVE_BUF_SIZE - m_leftOver;
 
       if (!end && count > maxReadCount)
           // must be a very very long line; sorry cannot handle it
           return NS_ERROR_FAILURE;
 
-      // make sure we don't insert another LF, accidentally
-      if (lastCharInPrevBuf == '\r' && *start == '\n')
-          start++;
-
       while (start && end)
       {
           if (m_outputStream &&
               PL_strncasecmp(start, "X-Mozilla-Status:", 17) &&
               PL_strncasecmp(start, "X-Mozilla-Status2:", 18) &&
               PL_strncmp(start, "From - ", 7))
           {
               rv = m_outputStream->Write(start, end-start, &writeCount);