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 243017 cb103a939041
parent 243016 e17127e00300
child 243018 17830430e6be
push id4364
push userryanvm@gmail.com
push date2015-01-24 16:33 +0000
treeherdermozilla-beta@34330baf2af6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley, sledru
bugs1124172
milestone36.0
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
@@ -1449,27 +1449,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);