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

Unified Diff: third_party/WebKit/Source/modules/encoding/TextEncoder.cpp

Issue 1414553002: Fix out-of-memory crashes related to ArrayBuffer allocation Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/encoding/TextEncoder.cpp
diff --git a/third_party/WebKit/Source/modules/encoding/TextEncoder.cpp b/third_party/WebKit/Source/modules/encoding/TextEncoder.cpp
index fdb5fc5c4fbd6c3b49a1f4651409ff31baececfc..0cf6d0f07074a810001a1555bc70e9bfc9a35f36 100644
--- a/third_party/WebKit/Source/modules/encoding/TextEncoder.cpp
+++ b/third_party/WebKit/Source/modules/encoding/TextEncoder.cpp
@@ -73,7 +73,7 @@ String TextEncoder::encoding() const
return name;
}
-PassRefPtr<DOMUint8Array> TextEncoder::encode(const String& input)
+PassRefPtr<DOMUint8Array> TextEncoder::encode(const String& input, ExceptionState& exceptionState)
{
CString result;
if (input.is8Bit())
@@ -84,7 +84,12 @@ PassRefPtr<DOMUint8Array> TextEncoder::encode(const String& input)
const char* buffer = result.data();
const unsigned char* unsignedBuffer = reinterpret_cast<const unsigned char*>(buffer);
- return DOMUint8Array::create(unsignedBuffer, result.length());
+ RefPtr<DOMUint8Array> output = DOMUint8Array::createOrNull(unsignedBuffer, result.length());
+ if (!output) {
+ exceptionState.throwRangeError("Out of memory. Could not allocate the array for storing the encoded data.");
+ }
+
+ return output.release();
}
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698