Bug 1516834 - Check if CopyData succeeded. r=nical, a=lizzard
authorsotaro <sotaro.ikeda.g@gmail.com>
Sat, 23 Feb 2019 10:52:38 -0500
changeset 516107 9d3241ed6cc5a21adfa97431541565cf1f26c275
parent 516106 f7afc2589d2cd268558ac274c2d6aa51caf209d3
child 516108 59a0b8b45c1e6a010397244e9030d9e3c80e2d86
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnical, lizzard
bugs1516834
milestone66.0
Bug 1516834 - Check if CopyData succeeded. r=nical, a=lizzard 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/RemoteVideoDecoderChild.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/RemoteVideoDecoderChild.cpp
+++ b/dom/media/ipc/RemoteVideoDecoderChild.cpp
@@ -68,29 +68,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::RecvVideoOutput(
     const RemoteVideoDataIPDL& aData) {
   AssertOnManagerThread();
 
   RefPtr<Image> image = DeserializeImage(aData.sdBuffer(), aData.frameSize());