diff --git a/dom/canvas/ImageBitmap.cpp b/dom/canvas/ImageBitmap.cpp index 4579c5f4e840..d0779470d8b5 100644 --- a/dom/canvas/ImageBitmap.cpp +++ b/dom/canvas/ImageBitmap.cpp @@ -950,9 +950,6 @@ UniquePtr ImageBitmap::ToCloneData() const { return nullptr; } - UniquePtr result(new ImageBitmapCloneData()); - result->mPictureRect = mPictureRect; - result->mAlphaType = mAlphaType; RefPtr surface = mData->GetAsSourceSurface(); if (!surface) { // It might just not be possible to get/map the surface. (e.g. from another @@ -960,10 +957,18 @@ UniquePtr ImageBitmap::ToCloneData() const { return nullptr; } - result->mSurface = surface->GetDataSurface(); - MOZ_ASSERT(result->mSurface); - result->mWriteOnly = mWriteOnly; + RefPtr dataSurface = surface->GetDataSurface(); + if (NS_WARN_IF(!dataSurface)) { + // This can reasonably fail in many cases (e.g. canvas state doesn't allow + // reading back the snapshot). + return nullptr; + } + auto result = MakeUnique(); + result->mPictureRect = mPictureRect; + result->mAlphaType = mAlphaType; + result->mSurface = std::move(dataSurface); + result->mWriteOnly = mWriteOnly; return result; }