Bug 1625685 - Avoid crash when deleting ALL attachments with one or more previously detached. r=mkmelin a=wsmwk
authorGene Smith <gds@chartertn.net>
Wed, 23 Sep 2020 16:09:25 -0400
changeset 40803 79b1e6ad28a14b22e30730d1a6625d7a31d4091c
parent 40802 34a9b787029905c452bcd8258dfaaf86402b3cc6
child 40804 5a38f179b694b0da4003fcd2a8edac48fa043683
push id406
push userthunderbird@calypsoblue.org
push dateMon, 19 Oct 2020 19:46:44 +0000
reviewersmkmelin, wsmwk
bugs1625685
Bug 1625685 - Avoid crash when deleting ALL attachments with one or more previously detached. r=mkmelin a=wsmwk
mailnews/base/src/nsMessenger.cpp
--- a/mailnews/base/src/nsMessenger.cpp
+++ b/mailnews/base/src/nsMessenger.cpp
@@ -561,17 +561,18 @@ NS_IMETHODIMP nsMessenger::SaveAttachmen
 
 NS_IMETHODIMP
 nsMessenger::DetachAttachmentsWOPrompts(
     nsIFile* aDestFolder, const nsTArray<nsCString>& aContentTypeArray,
     const nsTArray<nsCString>& aUrlArray,
     const nsTArray<nsCString>& aDisplayNameArray,
     const nsTArray<nsCString>& aMessageUriArray, nsIUrlListener* aListener) {
   NS_ENSURE_ARG_POINTER(aDestFolder);
-  MOZ_ASSERT(aContentTypeArray.Length() == aUrlArray.Length() ==
+  MOZ_ASSERT(aContentTypeArray.Length() == aUrlArray.Length() &&
+             aUrlArray.Length() ==  aDisplayNameArray.Length() &&
              aDisplayNameArray.Length() == aMessageUriArray.Length());
 
   if (!aContentTypeArray.Length()) return NS_OK;
   nsSaveAllAttachmentsState* saveState;
   nsCOMPtr<nsIFile> attachmentDestination;
   nsresult rv = aDestFolder->Clone(getter_AddRefs(attachmentDestination));
   NS_ENSURE_SUCCESS(rv, rv);
 
@@ -2124,17 +2125,18 @@ class nsAttachmentState {
 
 nsAttachmentState::nsAttachmentState() : mCurIndex(0) {}
 
 nsresult nsAttachmentState::Init(const nsTArray<nsCString>& aContentTypeArray,
                                  const nsTArray<nsCString>& aUrlArray,
                                  const nsTArray<nsCString>& aDisplayNameArray,
                                  const nsTArray<nsCString>& aMessageUriArray) {
   MOZ_ASSERT(aContentTypeArray.Length() > 0);
-  MOZ_ASSERT(aContentTypeArray.Length() == aUrlArray.Length() ==
+  MOZ_ASSERT(aContentTypeArray.Length() == aUrlArray.Length() &&
+             aUrlArray.Length() ==  aDisplayNameArray.Length() &&
              aDisplayNameArray.Length() == aMessageUriArray.Length());
 
   uint32_t count = aContentTypeArray.Length();
   mCurIndex = 0;
   mAttachmentArray.Clear();
   mAttachmentArray.SetCapacity(count);
 
   for (uint32_t u = 0; u < count; ++u) {
@@ -2514,18 +2516,20 @@ nsresult nsDelAttachListener::StartProce
   nsAutoCString sHeader("attach&del=");
   nsAutoCString detachToHeader("&detachTo=");
   for (uint32_t u = 0; u < mAttach->mAttachmentArray.Length(); ++u) {
     if (u > 0) {
       sHeader.Append(',');
       if (detaching) detachToHeader.Append(',');
     }
     partId = GetAttachmentPartId(mAttach->mAttachmentArray[u].mUrl.get());
-    nextField = PL_strchr(partId, '&');
-    sHeader.Append(partId, nextField ? nextField - partId : -1);
+    if (partId) {
+      nextField = PL_strchr(partId, '&');
+      sHeader.Append(partId, nextField ? nextField - partId : -1);
+    }
     if (detaching) detachToHeader.Append(mDetachedFileUris[u]);
   }
 
   if (detaching) sHeader.Append(detachToHeader);
   // stream this message to our listener converting it via the attachment mime
   // converter. The listener will just write the converted message straight to
   // disk.
   nsCOMPtr<nsISupports> listenerSupports;
@@ -2569,17 +2573,18 @@ nsMessenger::DetachAttachment(const nsAC
 NS_IMETHODIMP
 nsMessenger::DetachAllAttachments(const nsTArray<nsCString>& aContentTypeArray,
                                   const nsTArray<nsCString>& aUrlArray,
                                   const nsTArray<nsCString>& aDisplayNameArray,
                                   const nsTArray<nsCString>& aMessageUriArray,
                                   bool aSaveFirst,
                                   bool withoutWarning = false) {
   NS_ENSURE_ARG_MIN(aContentTypeArray.Length(), 1);
-  MOZ_ASSERT(aContentTypeArray.Length() == aUrlArray.Length() ==
+  MOZ_ASSERT(aContentTypeArray.Length() == aUrlArray.Length() &&
+             aUrlArray.Length() ==  aDisplayNameArray.Length() &&
              aDisplayNameArray.Length() == aMessageUriArray.Length());
 
   if (aSaveFirst)
     return SaveAllAttachments(aContentTypeArray, aUrlArray, aDisplayNameArray,
                               aMessageUriArray, true);
   else
     return DetachAttachments(aContentTypeArray, aUrlArray, aDisplayNameArray,
                              aMessageUriArray, nullptr, withoutWarning);