Title: [293065] branches/safari-613-branch/Source/WebCore
- Revision
- 293065
- Author
- [email protected]
- Date
- 2022-04-19 22:37:51 -0700 (Tue, 19 Apr 2022)
Log Message
Cherry-pick r291808. rdar://problem/91446363
FormDataConsumer callback happens more than once with an exception
https://bugs.webkit.org/show_bug.cgi?id=238091
In case of an error, it is not expected for the FormDataConsumer callback to happen
more than once with an exception. To avoid this, we introduce FormDataConsumer::didFail
which cancels/clears everything after reporting an error.
Reviewed by Youenn Fablet.
* Modules/fetch/FormDataConsumer.cpp:
(WebCore::FormDataConsumer::read):
(WebCore::FormDataConsumer::consumeFile):
(WebCore::FormDataConsumer::consumeBlob):
(WebCore::FormDataConsumer::didFail):
(WebCore::FormDataConsumer::cancel):
* Modules/fetch/FormDataConsumer.h:
(WebCore::FormDataConsumer::isCancelled):
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@291808 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Modified Paths
Diff
Modified: branches/safari-613-branch/Source/WebCore/ChangeLog (293064 => 293065)
--- branches/safari-613-branch/Source/WebCore/ChangeLog 2022-04-20 05:37:47 UTC (rev 293064)
+++ branches/safari-613-branch/Source/WebCore/ChangeLog 2022-04-20 05:37:51 UTC (rev 293065)
@@ -1,5 +1,50 @@
2022-04-19 Alan Coon <[email protected]>
+ Cherry-pick r291808. rdar://problem/91446363
+
+ FormDataConsumer callback happens more than once with an exception
+ https://bugs.webkit.org/show_bug.cgi?id=238091
+
+ In case of an error, it is not expected for the FormDataConsumer callback to happen
+ more than once with an exception. To avoid this, we introduce FormDataConsumer::didFail
+ which cancels/clears everything after reporting an error.
+
+ Reviewed by Youenn Fablet.
+
+ * Modules/fetch/FormDataConsumer.cpp:
+ (WebCore::FormDataConsumer::read):
+ (WebCore::FormDataConsumer::consumeFile):
+ (WebCore::FormDataConsumer::consumeBlob):
+ (WebCore::FormDataConsumer::didFail):
+ (WebCore::FormDataConsumer::cancel):
+ * Modules/fetch/FormDataConsumer.h:
+ (WebCore::FormDataConsumer::isCancelled):
+
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@291808 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2022-03-24 Gabriel Nava Marino <[email protected]>
+
+ FormDataConsumer callback happens more than once with an exception
+ https://bugs.webkit.org/show_bug.cgi?id=238091
+
+ In case of an error, it is not expected for the FormDataConsumer callback to happen
+ more than once with an exception. To avoid this, we introduce FormDataConsumer::didFail
+ which cancels/clears everything after reporting an error.
+
+ Reviewed by Youenn Fablet.
+
+ * Modules/fetch/FormDataConsumer.cpp:
+ (WebCore::FormDataConsumer::read):
+ (WebCore::FormDataConsumer::consumeFile):
+ (WebCore::FormDataConsumer::consumeBlob):
+ (WebCore::FormDataConsumer::didFail):
+ (WebCore::FormDataConsumer::cancel):
+ * Modules/fetch/FormDataConsumer.h:
+ (WebCore::FormDataConsumer::isCancelled):
+
+2022-04-19 Alan Coon <[email protected]>
+
Cherry-pick r288680. rdar://problem/91993398
Detect failed ThreadableLoader creation in FileReaderLoader.
Modified: branches/safari-613-branch/Source/WebCore/Modules/fetch/FormDataConsumer.cpp (293064 => 293065)
--- branches/safari-613-branch/Source/WebCore/Modules/fetch/FormDataConsumer.cpp 2022-04-20 05:37:47 UTC (rev 293064)
+++ branches/safari-613-branch/Source/WebCore/Modules/fetch/FormDataConsumer.cpp 2022-04-20 05:37:51 UTC (rev 293065)
@@ -47,8 +47,10 @@
void FormDataConsumer::read()
{
+ if (isCancelled())
+ return;
+
ASSERT(m_callback);
- ASSERT(m_context);
ASSERT(!m_blobLoader);
if (m_currentElementIndex >= m_formData->elements().size()) {
@@ -78,8 +80,7 @@
return;
if (!content) {
- if (weakThis->m_callback)
- weakThis->m_callback(Exception { InvalidStateError, "Unable to read form data file"_s });
+ weakThis->didFail(Exception { InvalidStateError, "Unable to read form data file"_s });
return;
}
@@ -99,8 +100,7 @@
return;
if (auto optionalErrorCode = loader->errorCode()) {
- if (weakThis->m_callback)
- weakThis->m_callback(Exception { InvalidStateError, "Failed to read form data blob"_s });
+ weakThis->didFail(Exception { InvalidStateError, "Failed to read form data blob"_s });
return;
}
@@ -110,10 +110,8 @@
m_blobLoader->start(blobURL, m_context.get(), FileReaderLoader::ReadAsArrayBuffer);
- if (!m_blobLoader || !m_blobLoader->isLoading()) {
- m_callback(Exception { InvalidStateError, "Unable to read form data blob"_s });
- m_blobLoader = nullptr;
- }
+ if (!m_blobLoader || !m_blobLoader->isLoading())
+ didFail(Exception { InvalidStateError, "Unable to read form data blob"_s });
}
void FormDataConsumer::consume(Span<const uint8_t> content)
@@ -128,13 +126,19 @@
read();
}
+void FormDataConsumer::didFail(auto&& exception)
+{
+ auto callback = std::exchange(m_callback, nullptr);
+ cancel();
+ if (callback)
+ callback(WTFMove(exception));
+}
+
void FormDataConsumer::cancel()
{
m_callback = nullptr;
- if (m_blobLoader) {
- m_blobLoader->cancel();
- m_blobLoader = nullptr;
- }
+ if (auto loader = std::exchange(m_blobLoader, { }))
+ loader->cancel();
m_context = nullptr;
}
Modified: branches/safari-613-branch/Source/WebCore/Modules/fetch/FormDataConsumer.h (293064 => 293065)
--- branches/safari-613-branch/Source/WebCore/Modules/fetch/FormDataConsumer.h 2022-04-20 05:37:47 UTC (rev 293064)
+++ branches/safari-613-branch/Source/WebCore/Modules/fetch/FormDataConsumer.h 2022-04-20 05:37:51 UTC (rev 293065)
@@ -53,6 +53,8 @@
void consume(Span<const uint8_t>);
void read();
+ void didFail(auto &&exception);
+ bool isCancelled() { return !m_context; }
Ref<FormData> m_formData;
RefPtr<ScriptExecutionContext> m_context;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes