Bug 1124172 - Abort read if there's nothing to read. r=bholley, a=sledru
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 22 Jan 2015 11:57:05 +1100
changeset 249392 07461392c0052be0f19ad27601ce1c204835bdc2
parent 249391 2555aadca9a481a59fa362fd21d0ae98e3cf9b72
child 249393 e3fd7a5f3fac218f6fe7192d13b27b9332c2773a
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley, sledru
bugs1124172
milestone37.0a2
Bug 1124172 - Abort read if there's nothing to read. r=bholley, a=sledru FileMediaResource::ReadFromCache assumes all data request will always be available. This may not always be true.
dom/media/MediaResource.cpp
--- a/dom/media/MediaResource.cpp
+++ b/dom/media/MediaResource.cpp
@@ -1452,27 +1452,33 @@ already_AddRefed<MediaResource> FileMedi
   return resource.forget();
 }
 
 nsresult FileMediaResource::ReadFromCache(char* aBuffer, int64_t aOffset, uint32_t aCount)
 {
   MutexAutoLock lock(mLock);
 
   EnsureSizeInitialized();
+  if (!aCount) {
+    return NS_OK;
+  }
   int64_t offset = 0;
   nsresult res = mSeekable->Tell(&offset);
   NS_ENSURE_SUCCESS(res,res);
   res = mSeekable->Seek(nsISeekableStream::NS_SEEK_SET, aOffset);
   NS_ENSURE_SUCCESS(res,res);
   uint32_t bytesRead = 0;
   do {
     uint32_t x = 0;
     uint32_t bytesToRead = aCount - bytesRead;
     res = mInput->Read(aBuffer, bytesToRead, &x);
     bytesRead += x;
+    if (!x) {
+      res = NS_ERROR_FAILURE;
+    }
   } while (bytesRead != aCount && res == NS_OK);
 
   // Reset read head to original position so we don't disturb any other
   // reading thread.
   nsresult seekres = mSeekable->Seek(nsISeekableStream::NS_SEEK_SET, offset);
 
   // If a read failed in the loop above, we want to return its failure code.
   NS_ENSURE_SUCCESS(res,res);