Bug 1194600 - Ensure plugin stream listener's buffer always has room for incoming data. r=jimm, a=ritu
authorAaron Klotz <aklotz@mozilla.com>
Tue, 25 Aug 2015 16:34:20 -0600
changeset 288924 c6dd528dba68d2dc8a6289d28ee03a78f58211f7
parent 288923 e0f3c1fde8c84af06aa2f158959cb721e7092856
child 288925 ab92db58d5e8aa6545683fa16849f6e70877c78e
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm, ritu
bugs1194600
milestone42.0a2
Bug 1194600 - Ensure plugin stream listener's buffer always has room for incoming data. r=jimm, a=ritu
dom/plugins/base/nsNPAPIPluginStreamListener.cpp
--- a/dom/plugins/base/nsNPAPIPluginStreamListener.cpp
+++ b/dom/plugins/base/nsNPAPIPluginStreamListener.cpp
@@ -531,34 +531,36 @@ nsNPAPIPluginStreamListener::OnDataAvail
     // and some plugins (e.g. acrobat) can fail. 
     if ((int32_t)mNPStreamWrapper->mNPStream.end < streamOffset)
       mNPStreamWrapper->mNPStream.end = streamOffset;
   }
   
   nsresult rv = NS_OK;
   while (NS_SUCCEEDED(rv) && length > 0) {
     if (input && length) {
-      if (mStreamBufferSize < mStreamBufferByteCount + length && mIsSuspended) {
+      if (mStreamBufferSize < mStreamBufferByteCount + length) {
         // We're in the ::OnDataAvailable() call that we might get
         // after suspending a request, or we suspended the request
         // from within this ::OnDataAvailable() call while there's
-        // still data in the input, and we don't have enough space to
-        // store what we got off the network. Reallocate our internal
-        // buffer.
+        // still data in the input, or we have resumed a previously
+        // suspended request and our buffer is already full, and we
+        // don't have enough space to store what we got off the network.
+        // Reallocate our internal buffer.
         mStreamBufferSize = mStreamBufferByteCount + length;
         char *buf = (char*)PR_Realloc(mStreamBuffer, mStreamBufferSize);
         if (!buf)
           return NS_ERROR_OUT_OF_MEMORY;
         
         mStreamBuffer = buf;
       }
-      
+
       uint32_t bytesToRead =
       std::min(length, mStreamBufferSize - mStreamBufferByteCount);
-      
+      MOZ_ASSERT(bytesToRead > 0);
+
       uint32_t amountRead = 0;
       rv = input->Read(mStreamBuffer + mStreamBufferByteCount, bytesToRead,
                        &amountRead);
       NS_ENSURE_SUCCESS(rv, rv);
       
       if (amountRead == 0) {
         NS_NOTREACHED("input->Read() returns no data, it's almost impossible "
                       "to get here");