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
--- 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();
}
};