Bug 1417113 - CloneableWithRangeMediaResource InputStreamReader::Read must always return what has been read from the buffer, r=jya
authorAndrea Marchesini <amarchesini@mozilla.com>
Mon, 27 Nov 2017 14:35:39 +0100
changeset 438258 ba2f695d60759bedca820d19da3b965806e5ecaf
parent 438257 6fe5938f3d590567eefb1b811620bcde4bf80018
child 438259 b2ac071a85449637bd88a8ba2d7496585893c0e7
push id117
push userfmarier@mozilla.com
push dateTue, 28 Nov 2017 20:17:16 +0000
reviewersjya
bugs1417113
milestone59.0a1
Bug 1417113 - CloneableWithRangeMediaResource InputStreamReader::Read must always return what has been read from the buffer, r=jya Before this patch, InputStreamReader::Read was returning NS_OK without updating aRead if SyncRead() was unable to read the requested amount of data from the stream. Just because SyncRead() was executing in a do/while loop, we must always update aRead with what was been read so far.
dom/media/CloneableWithRangeMediaResource.cpp
--- a/dom/media/CloneableWithRangeMediaResource.cpp
+++ b/dom/media/CloneableWithRangeMediaResource.cpp
@@ -39,17 +39,20 @@ public:
 
   nsresult
   Read(char* aBuffer, uint32_t aSize, uint32_t* aRead)
   {
     uint32_t done = 0;
     do {
       uint32_t read;
       nsresult rv = SyncRead(aBuffer + done, aSize - done, &read);
-      if (NS_WARN_IF(NS_FAILED(rv)) || read == 0) {
+      if (NS_SUCCEEDED(rv) && read == 0) {
+        break;
+      }
+      if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
       done += read;
     } while(done != aSize);
 
     *aRead = done;
     return NS_OK;
   }
@@ -74,17 +77,17 @@ private:
 
   nsresult
   SyncRead(char* aBuffer, uint32_t aSize, uint32_t* aRead)
   {
     while (1) {
       nsresult rv = mStream->Read(aBuffer, aSize, aRead);
       // All good.
       if (rv == NS_BASE_STREAM_CLOSED || NS_SUCCEEDED(rv)) {
-        return rv;
+        return NS_OK;
       }
 
       // An error.
       if (NS_FAILED(rv) && rv != NS_BASE_STREAM_WOULD_BLOCK) {
         return rv;
       }
 
       // We need to proceed async.