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

Unified Diff: third_party/WebKit/Source/core/html/ImageData.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/core/html/ImageData.cpp
diff --git a/third_party/WebKit/Source/core/html/ImageData.cpp b/third_party/WebKit/Source/core/html/ImageData.cpp
index f0cec65d2ecd00cf4d5c6b57a1d593615b16ecda..428c86136683e18a577f1133df04ae0ee14d143a 100644
--- a/third_party/WebKit/Source/core/html/ImageData.cpp
+++ b/third_party/WebKit/Source/core/html/ImageData.cpp
@@ -36,18 +36,22 @@
namespace blink {
-ImageData* ImageData::create(const IntSize& size)
+ImageData* ImageData::create(const IntSize& size, ExceptionState& exceptionState)
{
Checked<int, RecordOverflow> dataSize = 4;
dataSize *= size.width();
dataSize *= size.height();
- if (dataSize.hasOverflowed() || dataSize.unsafeGet() < 0)
+ if (dataSize.hasOverflowed() || dataSize.unsafeGet() < 0) {
+ exceptionState.throwDOMException(IndexSizeError, "The requested image size exceeds the supported range.");
return nullptr;
+ }
RefPtr<DOMUint8ClampedArray> byteArray =
DOMUint8ClampedArray::createOrNull(dataSize.unsafeGet());
- if (!byteArray)
+ if (!byteArray) {
+ exceptionState.throwRangeError("ImageData object creation failed due to insufficient available memory.");
return nullptr;
+ }
return new ImageData(size, byteArray.release());
}
@@ -57,12 +61,11 @@ ImageData* ImageData::create(const IntSize& size, PassRefPtr<DOMUint8ClampedArra
Checked<int, RecordOverflow> dataSize = 4;
dataSize *= size.width();
dataSize *= size.height();
- if (dataSize.hasOverflowed())
- return nullptr;
-
- if (dataSize.unsafeGet() < 0
- || static_cast<unsigned>(dataSize.unsafeGet()) > byteArray->length())
+ if (dataSize.hasOverflowed()
+ || dataSize.unsafeGet() < 0
+ || static_cast<unsigned>(dataSize.unsafeGet()) > byteArray->length()) {
return nullptr;
+ }
return new ImageData(size, byteArray);
}
@@ -87,7 +90,7 @@ ImageData* ImageData::create(unsigned width, unsigned height, ExceptionState& ex
RefPtr<DOMUint8ClampedArray> byteArray =
DOMUint8ClampedArray::createOrNull(dataSize.unsafeGet());
if (!byteArray) {
- exceptionState.throwDOMException(V8GeneralError, "Out of memory at ImageData creation");
+ exceptionState.throwRangeError("ImageData object creation failed due to insufficient available memory.");
return nullptr;
}
« no previous file with comments | « third_party/WebKit/Source/core/html/ImageData.h ('k') | third_party/WebKit/Source/core/imagebitmap/ImageBitmapFactories.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698