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

Unified Diff: third_party/WebKit/Source/platform/graphics/ImageBuffer.cpp

Issue 1775613002: Throw a RangeError exception from get/createImageData when out of memory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix assert in test Created 4 years, 9 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
« no previous file with comments | « third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2DAPITest.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/graphics/ImageBuffer.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/ImageBuffer.cpp b/third_party/WebKit/Source/platform/graphics/ImageBuffer.cpp
index 58b33b4e56ad98284fcc6bd9584a97adb2bebd28..43b143fad962bbc182b03b7485392a41bc426fe5 100644
--- a/third_party/WebKit/Source/platform/graphics/ImageBuffer.cpp
+++ b/third_party/WebKit/Source/platform/graphics/ImageBuffer.cpp
@@ -292,7 +292,12 @@ bool ImageBuffer::getImageData(Multiply multiplied, const IntRect& rect, WTF::Ar
return false;
if (!isSurfaceValid()) {
- WTF::ArrayBufferContents result(rect.width() * rect.height(), 4, WTF::ArrayBufferContents::NotShared, WTF::ArrayBufferContents::ZeroInitialize);
+ size_t allocSizeInBytes = rect.width() * rect.height() * 4;
+ void* data;
+ WTF::ArrayBufferContents::allocateMemoryOrNull(allocSizeInBytes, WTF::ArrayBufferContents::ZeroInitialize, data);
+ if (!data)
+ return false;
+ WTF::ArrayBufferContents result(data, allocSizeInBytes, WTF::ArrayBufferContents::NotShared);
result.transfer(contents);
return true;
}
@@ -308,12 +313,13 @@ bool ImageBuffer::getImageData(Multiply multiplied, const IntRect& rect, WTF::Ar
|| rect.y() < 0
|| rect.maxX() > m_surface->size().width()
|| rect.maxY() > m_surface->size().height();
- WTF::ArrayBufferContents result(
- rect.width() * rect.height(), 4,
- WTF::ArrayBufferContents::NotShared,
- mayHaveStrayArea
- ? WTF::ArrayBufferContents::ZeroInitialize
- : WTF::ArrayBufferContents::DontInitialize);
+ size_t allocSizeInBytes = rect.width() * rect.height() * 4;
+ void* data;
+ WTF::ArrayBufferContents::InitializationPolicy initializationPolicy = mayHaveStrayArea ? WTF::ArrayBufferContents::ZeroInitialize : WTF::ArrayBufferContents::DontInitialize;
+ WTF::ArrayBufferContents::allocateMemoryOrNull(allocSizeInBytes, initializationPolicy, data);
+ if (!data)
+ return false;
+ WTF::ArrayBufferContents result(data, allocSizeInBytes, WTF::ArrayBufferContents::NotShared);
SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType : kUnpremul_SkAlphaType;
SkImageInfo info = SkImageInfo::Make(rect.width(), rect.height(), kRGBA_8888_SkColorType, alphaType);
« no previous file with comments | « third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2DAPITest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698