Bug 1369724: Fix setting size for fake H264 codec r=jya
authorRandell Jesup <rjesup@jesup.org>
Fri, 02 Jun 2017 09:59:36 -0400
changeset 412502 99cc18bf162ac13654adbc515d999e6590cce6dc
parent 412501 4d98a42a482f6c73e24b2e9535e4e93643284a31
child 412503 0ed2ebbb0b73f2b241318a17e9774da28277975c
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1369724, 1341285
milestone55.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 1369724: Fix setting size for fake H264 codec r=jya From bug 1341285 MozReview-Commit-ID: E6g6phiQC5H
dom/media/gmp-plugin-openh264/gmp-fake-openh264.cpp
media/webrtc/signaling/src/media-conduit/WebrtcGmpVideoCodec.cpp
--- a/dom/media/gmp-plugin-openh264/gmp-fake-openh264.cpp
+++ b/dom/media/gmp-plugin-openh264/gmp-fake-openh264.cpp
@@ -200,17 +200,18 @@ class FakeVideoEncoder : public GMPVideo
                                (frame_type  == kGMPKeyFrame ? sizeof(uint32_t) + BIG_FRAME : 0));
     if (err != GMPNoErr) {
       GMPLOG (GL_ERROR, "Error allocating frame data");
       f->Destroy();
       return;
     }
     memcpy(f->Buffer(), &eframe, sizeof(eframe));
     if (frame_type  == kGMPKeyFrame) {
-      *((uint32_t*) f->Buffer() + sizeof(eframe)) = BIG_FRAME;
+      // set the size for the fake iframe
+      *((uint32_t*) (f->Buffer() + sizeof(eframe))) = BIG_FRAME;
     }
 
     f->SetEncodedWidth (inputImage->Width());
     f->SetEncodedHeight (inputImage->Height());
     f->SetTimeStamp (inputImage->Timestamp());
     f->SetFrameType (frame_type);
     f->SetCompleteFrame (true);
     f->SetBufferType(GMP_BufferLength32);
--- a/media/webrtc/signaling/src/media-conduit/WebrtcGmpVideoCodec.cpp
+++ b/media/webrtc/signaling/src/media-conduit/WebrtcGmpVideoCodec.cpp
@@ -586,21 +586,22 @@ WebrtcGmpVideoEncoder::Encoded(GMPVideoE
         case GMP_BufferLength32:
           // presumes we can do unaligned loads
           size = *(reinterpret_cast<uint32_t*>(buffer));
           buffer += 4;
           break;
         default:
           MOZ_CRASH("GMP_BufferType already handled in switch above");
       }
-      if (buffer+size > end) {
+      MOZ_ASSERT(size != 0 &&
+                 buffer+size <= end); // in non-debug code, don't crash in this case
+      if (size == 0 || buffer+size > end) {
         // XXX see above - should we kill the plugin for returning extra bytes?  Probably
         LOG(LogLevel::Error,
-            ("GMP plugin returned badly formatted encoded data: end is %td bytes past buffer end",
-             buffer+size - end));
+            ("GMP plugin returned badly formatted encoded data: buffer=%p, size=%d, end=%p", buffer, size, end));
         return;
       }
       // XXX optimize by making buffer an offset
       nal_entry nal = {((uint32_t) (buffer-aEncodedFrame->Buffer())), (uint32_t) size};
       nals.AppendElement(nal);
       buffer += size;
       // on last one, buffer == end normally
     }