Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(440)

Unified Diff: third_party/WebKit/Source/modules/fetch/BodyStreamBuffer.cpp

Issue 1414553002: Fix out-of-memory crashes related to ArrayBuffer allocation Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase+more tweaks Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/fetch/BodyStreamBuffer.cpp
diff --git a/third_party/WebKit/Source/modules/fetch/BodyStreamBuffer.cpp b/third_party/WebKit/Source/modules/fetch/BodyStreamBuffer.cpp
index f3efdfc5fa6f02cc035f7e2117616d3a56184313..b8462557b581dd3d84a48516efc9ad53cc8559f7 100644
--- a/third_party/WebKit/Source/modules/fetch/BodyStreamBuffer.cpp
+++ b/third_party/WebKit/Source/modules/fetch/BodyStreamBuffer.cpp
@@ -213,9 +213,27 @@ void BodyStreamBuffer::processData()
WebDataConsumerHandle::Result result = m_reader->beginRead(&buffer, WebDataConsumerHandle::FlagNone, &available);
switch (result) {
case WebDataConsumerHandle::Ok:
- m_streamNeedsMore = m_stream->enqueue(DOMUint8Array::create(static_cast<const unsigned char*>(buffer), available));
- m_reader->endRead(available);
- break;
+ {
+ // TODO(junov): crbug.com/536816
+ // Use createOrNull instead of deprecatedCreateOrCrash in order to
+ // fail gracefully when allocation fails. It would probably be
+ // appropriate to do something like this to handle the failure:
+ //
+ // if (!domArray) {
+ // m_reader = nullptr;
+ // m_stream->error(DOMException::create(V8RangeError, "Out of Memory."));
+ // m_handle.clear();
+ // }
+ //
+ // The spec would need to be amended to support that behavior.
+ // Alternately, we could just proceed with domArray being null if it
+ // is ascertained that silently dropping data is acceptable when the
+ // alternative is to crash with an out-of-memory exception.
+ RefPtr<DOMUint8Array> domArray = DOMUint8Array::deprecatedCreateOrCrash(static_cast<const unsigned char*>(buffer), available);
+ m_streamNeedsMore = m_stream->enqueue(domArray);
+ m_reader->endRead(available);
+ }
+ return;
case WebDataConsumerHandle::Done:
close();

Powered by Google App Engine
This is Rietveld 408576698