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

Unified Diff: third_party/WebKit/Source/modules/websockets/DocumentWebSocketChannel.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 and applied senorblanco+haraken feedbac Created 5 years, 2 months 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/websockets/DocumentWebSocketChannel.cpp
diff --git a/third_party/WebKit/Source/modules/websockets/DocumentWebSocketChannel.cpp b/third_party/WebKit/Source/modules/websockets/DocumentWebSocketChannel.cpp
index 684d0769189f78cc87681f83bcded743e9ed103b..ac8a688aa748ce3be8eee7d397400f74ff576d83 100644
--- a/third_party/WebKit/Source/modules/websockets/DocumentWebSocketChannel.cpp
+++ b/third_party/WebKit/Source/modules/websockets/DocumentWebSocketChannel.cpp
@@ -100,7 +100,14 @@ void DocumentWebSocketChannel::BlobLoader::cancel()
void DocumentWebSocketChannel::BlobLoader::didFinishLoading()
{
- m_channel->didFinishLoadingBlob(m_loader.arrayBufferResult());
+ RefPtr<DOMArrayBuffer> result = m_loader.arrayBufferResultOrNull();
+ // TODO(junov): crbug.com/536816
+ // Is there a better way to handle an allocation failure instead
+ // of crashing? Would it be okay to fail silently by passing a nullptr?
+ // Should we call didFailLoadingBlob? If so, with which ErrorCode?
+ // Spec may need to be ammended for this.
+ RELEASE_ASSERT(result); // This is essentially an out-of-memory crash
+ m_channel->didFinishLoadingBlob(result.release());
// |this| is deleted here.
}
@@ -199,7 +206,10 @@ void DocumentWebSocketChannel::send(const DOMArrayBuffer& buffer, unsigned byteO
// buffer.slice copies its contents.
// FIXME: Reduce copy by sending the data immediately when we don't need to
// queue the data.
- m_messages.append(adoptPtr(new Message(buffer.slice(byteOffset, byteOffset + byteLength))));
+ RefPtr<DOMArrayBuffer> slice = buffer.sliceOrNull(byteOffset, byteOffset + byteLength);
+ // FIXME: Could we propagate a RangeError exception from here instead the following assert?
+ RELEASE_ASSERT(slice); // This is an out-of-memory condition.
+ m_messages.append(adoptPtr(new Message(slice.release())));
processSendQueue();
}

Powered by Google App Engine
This is Rietveld 408576698