Bug 1516834 - Check if CopyData succeeded r=nical
authorsotaro <sotaro.ikeda.g@gmail.com>
Tue, 19 Feb 2019 09:12:47 +0900
changeset 459830 0daaf4ad9645
parent 459829 e772a34b885e
child 459831 ee6e77950205
push id35575
push usercbrindusan@mozilla.com
push dateTue, 19 Feb 2019 04:40:03 +0000
treeherdermozilla-central@ee6e77950205 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnical
bugs1516834
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1516834 - Check if CopyData succeeded r=nical When CopyData failed, an image does not have valid data. It should not be used. Differential Revision: https://phabricator.services.mozilla.com/D19746
dom/media/VideoFrameContainer.cpp
dom/media/ipc/RemoteVideoDecoder.cpp
--- a/dom/media/VideoFrameContainer.cpp
+++ b/dom/media/VideoFrameContainer.cpp
@@ -75,26 +75,26 @@ void VideoFrameContainer::UpdatePrincipa
     const ImageContainer::FrameID& aFrameID) {
   if (mPendingPrincipalHandle == aPrincipalHandle) {
     return;
   }
   mPendingPrincipalHandle = aPrincipalHandle;
   mFrameIDForPendingPrincipalHandle = aFrameID;
 }
 
-static void SetImageToBlackPixel(PlanarYCbCrImage* aImage) {
+static bool SetImageToBlackPixel(PlanarYCbCrImage* aImage) {
   uint8_t blackPixel[] = {0x10, 0x80, 0x80};
 
   PlanarYCbCrData data;
   data.mYChannel = blackPixel;
   data.mCbChannel = blackPixel + 1;
   data.mCrChannel = blackPixel + 2;
   data.mYStride = data.mCbCrStride = 1;
   data.mPicSize = data.mYSize = data.mCbCrSize = gfx::IntSize(1, 1);
-  aImage->CopyData(data);
+  return aImage->CopyData(data);
 }
 
 class VideoFrameContainerInvalidateRunnable : public Runnable {
  public:
   explicit VideoFrameContainerInvalidateRunnable(
       VideoFrameContainer* aVideoFrameContainer)
       : Runnable("VideoFrameContainerInvalidateRunnable"),
         mVideoFrameContainer(aVideoFrameContainer) {}
@@ -137,21 +137,23 @@ void VideoFrameContainer::SetCurrentFram
     Image* image = frame->GetImage();
     CONTAINER_LOG(
         LogLevel::Verbose,
         ("VideoFrameContainer %p writing video frame %p (%d x %d)", this, image,
          frame->GetIntrinsicSize().width, frame->GetIntrinsicSize().height));
 
     if (frame->GetForceBlack()) {
       if (!mBlackImage) {
-        mBlackImage = GetImageContainer()->CreatePlanarYCbCrImage();
-        if (mBlackImage) {
+        RefPtr<Image> blackImage = GetImageContainer()->CreatePlanarYCbCrImage();
+        if (blackImage) {
           // Sets the image to a single black pixel, which will be scaled to
           // fill the rendered size.
-          SetImageToBlackPixel(mBlackImage->AsPlanarYCbCrImage());
+          if (SetImageToBlackPixel(blackImage->AsPlanarYCbCrImage())) {
+            mBlackImage = blackImage;
+          }
         }
       }
       if (mBlackImage) {
         image = mBlackImage;
       }
     }
     // Don't append null image to the newImages.
     if (!image) {
--- a/dom/media/ipc/RemoteVideoDecoder.cpp
+++ b/dom/media/ipc/RemoteVideoDecoder.cpp
@@ -59,29 +59,34 @@ RefPtr<mozilla::layers::Image> RemoteVid
   pData.mYUVColorSpace = descriptor.yUVColorSpace();
   pData.mYChannel = ImageDataSerializer::GetYChannel(buffer, descriptor);
   pData.mCbChannel = ImageDataSerializer::GetCbChannel(buffer, descriptor);
   pData.mCrChannel = ImageDataSerializer::GetCrChannel(buffer, descriptor);
 
   // images coming from AOMDecoder are RecyclingPlanarYCbCrImages.
   RefPtr<RecyclingPlanarYCbCrImage> image =
       new RecyclingPlanarYCbCrImage(mBufferRecycleBin);
-  image->CopyData(pData);
+  bool setData = image->CopyData(pData);
+  MOZ_ASSERT(setData);
 
   switch (memOrShmem.type()) {
     case MemoryOrShmem::Tuintptr_t:
       delete[] reinterpret_cast<uint8_t*>(memOrShmem.get_uintptr_t());
       break;
     case MemoryOrShmem::TShmem:
       DeallocShmem(memOrShmem.get_Shmem());
       break;
     default:
       MOZ_ASSERT(false, "Unknown MemoryOrShmem type");
   }
 
+  if (!setData) {
+    return nullptr;
+  }
+
   return image;
 }
 
 mozilla::ipc::IPCResult RemoteVideoDecoderChild::RecvOutput(
     const DecodedOutputIPDL& aDecodedData) {
   AssertOnManagerThread();
   MOZ_ASSERT(aDecodedData.type() == DecodedOutputIPDL::TRemoteVideoDataIPDL);
   const RemoteVideoDataIPDL& aData = aDecodedData.get_RemoteVideoDataIPDL();