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

Unified Diff: third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp

Issue 2361493003: Make toDataURL robust with respect to allocation failures (Closed)
Patch Set: drive-by fix for toBlob Created 4 years, 3 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp
diff --git a/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp b/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp
index 7ca764f3bd3747d000e47bff2860c2bc569530db..a906c7f9f67c9e10cfd555f9d65879b94e602b8d 100644
--- a/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp
+++ b/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp
@@ -625,7 +625,7 @@ ImageData* HTMLCanvasElement::toImageData(SourceDrawingBuffer sourceBuffer, Snap
m_context->paintRenderingResultsToCanvas(sourceBuffer);
imageData = ImageData::create(m_size);
- if (hasImageBuffer()) {
+ if (imageData && hasImageBuffer()) {
sk_sp<SkImage> snapshot = buffer()->newSkImageSnapshot(PreferNoAcceleration, reason);
if (snapshot) {
SkImageInfo imageInfo = SkImageInfo::Make(width(), height(), kRGBA_8888_SkColorType, kUnpremul_SkAlphaType);
@@ -637,7 +637,7 @@ ImageData* HTMLCanvasElement::toImageData(SourceDrawingBuffer sourceBuffer, Snap
imageData = ImageData::create(m_size);
- if (!m_context)
+ if (!m_context || !imageData)
return imageData;
DCHECK(m_context->is2d());
@@ -661,6 +661,9 @@ String HTMLCanvasElement::toDataURLInternal(const String& mimeType, const double
ImageData* imageData = toImageData(sourceBuffer, SnapshotReasonToDataURL);
+ if (!imageData) // allocation failure
+ return String("data:,");
+
return ImageDataBuffer(imageData->size(), imageData->data()->data()).toDataURL(encodingMimeType, quality);
}
@@ -745,6 +748,12 @@ void HTMLCanvasElement::toBlob(BlobCallback* callback, const String& mimeType, c
ImageData* imageData = toImageData(BackBuffer, SnapshotReasonToBlob);
+ if (!imageData) {
+ // ImageData allocation faillure
+ TaskRunnerHelper::get(TaskType::CanvasBlobSerialization, &document())->postTask(BLINK_FROM_HERE, WTF::bind(&BlobCallback::handleEvent, wrapPersistent(callback), nullptr));
+ return;
+ }
+
CanvasAsyncBlobCreator* asyncCreator = CanvasAsyncBlobCreator::create(imageData->data(), encodingMimeType, imageData->size(), callback, startTime, document());
bool useIdlePeriodScheduling = (encodingMimeType != "image/webp");
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698