From baebc834321800b5693a929fb63d5b3dcc4fb279 Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Wed, 22 Mar 2017 14:57:25 -0400 Subject: [PATCH] Bug 1347632 - make RecordedSourceSurfaceCreation fallible. r=tobytailor MozReview-Commit-ID: G4x3zTluGb4 --- gfx/2d/RecordedEvent.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/gfx/2d/RecordedEvent.cpp b/gfx/2d/RecordedEvent.cpp index 6d3688ac05f3..370ac98d1ffe 100644 --- a/gfx/2d/RecordedEvent.cpp +++ b/gfx/2d/RecordedEvent.cpp @@ -1299,6 +1299,10 @@ RecordedSourceSurfaceCreation::~RecordedSourceSurfaceCreation() bool RecordedSourceSurfaceCreation::PlayEvent(Translator *aTranslator) const { + if (!mData) { + return false; + } + RefPtr src = aTranslator->GetReferenceDrawTarget()-> CreateSourceSurfaceFromData(mData, mSize, mSize.width * BytesPerPixel(mFormat), mFormat); aTranslator->AddSourceSurface(mRefPtr, src); @@ -1311,6 +1315,7 @@ RecordedSourceSurfaceCreation::RecordToStream(ostream &aStream) const WriteElement(aStream, mRefPtr); WriteElement(aStream, mSize); WriteElement(aStream, mFormat); + MOZ_ASSERT(mData); for (int y = 0; y < mSize.height; y++) { aStream.write((const char*)mData + y * mStride, BytesPerPixel(mFormat) * mSize.width); } @@ -1322,8 +1327,12 @@ RecordedSourceSurfaceCreation::RecordedSourceSurfaceCreation(istream &aStream) ReadElement(aStream, mRefPtr); ReadElement(aStream, mSize); ReadElement(aStream, mFormat); - mData = (uint8_t*)new char[mSize.width * mSize.height * BytesPerPixel(mFormat)]; - aStream.read((char*)mData, mSize.width * mSize.height * BytesPerPixel(mFormat)); + mData = (uint8_t*)new (fallible) char[mSize.width * mSize.height * BytesPerPixel(mFormat)]; + if (!mData) { + gfxWarning() << "RecordedSourceSurfaceCreation failed to allocate data"; + } else { + aStream.read((char*)mData, mSize.width * mSize.height * BytesPerPixel(mFormat)); + } } void