Bug 1495698 - Fix hang when HTML signature references non-existent image. r=aceman
authorJorg K <jorgk@jorgk.com>
Fri, 05 Oct 2018 14:22:32 +0200
changeset 33304 ff185577e79d45203202dd6e9f587fa6888a505a
parent 33303 9766dccdd8b8e23e7ac26f3bfa94449e8b5bf40d
child 33305 b4b14a46f3f83f60dc13628b250903a1b12c2eb3
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
reviewersaceman
bugs1495698
Bug 1495698 - Fix hang when HTML signature references non-existent image. r=aceman
mailnews/compose/src/nsMsgCompose.cpp
mailnews/compose/src/nsMsgCompose.h
--- a/mailnews/compose/src/nsMsgCompose.cpp
+++ b/mailnews/compose/src/nsMsgCompose.cpp
@@ -4205,22 +4205,22 @@ nsMsgCompose::LoadDataFromFile(nsIFile *
 }
 
 /**
  * If the data contains file URLs, convert them to data URLs instead.
  * This is intended to be used in for signature files, so that we can make sure
  * images loaded into the editor are available on send.
  */
 nsresult
-nsMsgCompose::ReplaceFileURLs(nsAutoString &aData)
+nsMsgCompose::ReplaceFileURLs(nsString &aData)
 {
   int32_t fPos;
   int32_t offset = -1;  // We're using RFind(), so offset -1 is from the very right.
 
-  // XXX This code is rather incompelte since it looks for "file://" even
+  // XXX This code is rather incomplete since it looks for "file://" even
   // outside tags.
   while ((fPos = aData.RFind("file://", true, offset)) != kNotFound) {
     bool quoted = false;
     char16_t q = 'x';  // initialise to anything to keep compilers happy.
     if (fPos > 0) {
       q = aData.CharAt(fPos - 1);
       quoted = (q == '"' || q == '\'');
     }
@@ -4248,17 +4248,19 @@ nsMsgCompose::ReplaceFileURLs(nsAutoStri
     fileURL = Substring(aData, fPos, end - fPos);
     nsString dataURL;
     nsresult rv = DataURLForFileURL(fileURL, dataURL);
     // If this one failed, maybe because the file wasn't found,
     // continue to process the next one.
     if (NS_SUCCEEDED(rv)) {
       aData.Replace(fPos, end - fPos, dataURL);
     }
-    offset = fPos;
+    if (fPos == 0)
+      break;
+    offset = fPos - 1;
   }
   return NS_OK;
 }
 
 nsresult
 nsMsgCompose::DataURLForFileURL(const nsAString &aFileURL, nsAString &aDataURL)
 {
   nsresult rv;
--- a/mailnews/compose/src/nsMsgCompose.h
+++ b/mailnews/compose/src/nsMsgCompose.h
@@ -87,17 +87,17 @@ protected:
                            nsTArray<nsMsgMailList>& allMailListArray,
                            nsTArray<nsMsgMailList>& mailListResolved,
                            nsTArray<nsMsgRecipient>& aListMembers);
   void TagConvertible(mozilla::dom::Element *node,  int32_t *_retval);
   void _NodeTreeConvertible(mozilla::dom::Element *node, int32_t *_retval);
   nsresult MoveToAboveQuote(void);
   nsresult MoveToBeginningOfDocument(void);
   nsresult MoveToEndOfDocument(void);
-  nsresult ReplaceFileURLs(nsAutoString &sigData);
+  nsresult ReplaceFileURLs(nsString &sigData);
   nsresult DataURLForFileURL(const nsAString &aFileURL, nsAString &aDataURL);
 
 // 3 = To, Cc, Bcc
 #define MAX_OF_RECIPIENT_ARRAY 3
   typedef nsTArray<nsMsgRecipient> RecipientsArray[MAX_OF_RECIPIENT_ARRAY];
   /**
    * This method parses the compose fields and associates email addresses with
    * the relevant cards from the address books.