Bug 1464648 - Bail early when parsing empty form data (to avoid NS_NOTREACHED assertion failure). r?baku draft
authorChris Peterson <cpeterson@mozilla.com>
Sat, 26 May 2018 16:49:39 -0700
changeset 802570 aff5a0cee23ea6eeb769a68884249a27dccb2c7e
parent 800319 4e9446f9e8f0a75c7ffe063f1dfb311cc90d56cf
push id111919
push usercpeterson@mozilla.com
push dateFri, 01 Jun 2018 07:22:59 +0000
reviewersbaku
bugs1464648
milestone62.0a1
Bug 1464648 - Bail early when parsing empty form data (to avoid NS_NOTREACHED assertion failure). r?baku This NS_NOTREACHED("Should never reach here.") assertion fails on the following test case of the testing/web-platform/tests/fetch/api/response/response-consume-empty.html web platform test: checkResponseWithNoBody("formData with correct multipart type (error case)", checkBodyFormDataError, [["Content-Type", 'multipart/form-data; boundary="boundary"']]); MozReview-Commit-ID: 1rKRBDrqybJ
dom/base/BodyUtil.cpp
--- a/dom/base/BodyUtil.cpp
+++ b/dom/base/BodyUtil.cpp
@@ -291,16 +291,20 @@ public:
   FormDataParser(const nsACString& aMimeType, const nsACString& aData, nsIGlobalObject* aParent)
     : mMimeType(aMimeType), mData(aData), mState(START_PART), mParentObject(aParent)
   {
   }
 
   bool
   Parse()
   {
+    if (mData.IsEmpty()) {
+      return false;
+    }
+
     // Determine boundary from mimetype.
     const char* boundaryId = nullptr;
     boundaryId = strstr(mMimeType.BeginWriting(), "boundary");
     if (!boundaryId) {
       return false;
     }
 
     boundaryId = strchr(boundaryId, '=');
@@ -382,17 +386,17 @@ public:
           mState = START_PART;
           break;
 
         default:
           MOZ_CRASH("Invalid case");
       }
     }
 
-    NS_NOTREACHED("Should never reach here.");
+    MOZ_ASSERT_UNREACHABLE("Should never reach here.");
     return false;
   }
 
   already_AddRefed<FormData> GetFormData()
   {
     return mFormData.forget();
   }
 };