Bug 1360185 - Use of IPCBlob in IndexedDB - part 6 - FileReaderSync should check if the streams are already closed, r=janv
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 23 May 2017 07:53:35 +0200
changeset 360072 e2357be6f07bd385e4bf7eb3d39885c478c84d24
parent 360071 ed16949f745637b318031bd06357c2a231d0fb6d
child 360073 c18a711575f5559d41fbe7eb2eff9d1ffea02a24
push id90568
push useramarchesini@mozilla.com
push dateTue, 23 May 2017 06:04:28 +0000
treeherdermozilla-inbound@e2357be6f07b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjanv
bugs1360185
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 1360185 - Use of IPCBlob in IndexedDB - part 6 - FileReaderSync should check if the streams are already closed, r=janv
dom/workers/FileReaderSync.cpp
--- a/dom/workers/FileReaderSync.cpp
+++ b/dom/workers/FileReaderSync.cpp
@@ -217,19 +217,23 @@ FileReaderSync::ReadAsText(Blob& aBlob,
   }
 
   nsCOMPtr<nsIInputStream> syncStream;
   aRv = ConvertAsyncToSyncStream(stream, getter_AddRefs(syncStream));
   if (NS_WARN_IF(aRv.Failed())) {
     return;
   }
 
-  aRv = multiplexStream->AppendStream(syncStream);
-  if (NS_WARN_IF(aRv.Failed())) {
-    return;
+  // ConvertAsyncToSyncStream returns a null syncStream if the stream has been
+  // already closed or there is nothing to read.
+  if (syncStream) {
+    aRv = multiplexStream->AppendStream(syncStream);
+    if (NS_WARN_IF(aRv.Failed())) {
+      return;
+    }
   }
 
   aRv = ConvertStream(multiplexStream, encoding.get(), aResult);
   if (NS_WARN_IF(aRv.Failed())) {
     return;
   }
 }
 
@@ -257,16 +261,18 @@ FileReaderSync::ReadAsDataURL(Blob& aBlo
   }
 
   nsCOMPtr<nsIInputStream> syncStream;
   aRv = ConvertAsyncToSyncStream(stream, getter_AddRefs(syncStream));
   if (NS_WARN_IF(aRv.Failed())) {
     return;
   }
 
+  MOZ_ASSERT(syncStream);
+
   uint64_t size;
   aRv = syncStream->Available(&size);
   if (NS_WARN_IF(aRv.Failed())) {
     return;
   }
 
   uint64_t blobSize = aBlob.GetSize(aRv);
   if (NS_WARN_IF(aRv.Failed())){
@@ -471,16 +477,22 @@ FileReaderSync::ConvertAsyncToSyncStream
   // If the stream is not async, we just need it to be bufferable.
   nsCOMPtr<nsIAsyncInputStream> asyncStream = do_QueryInterface(aAsyncStream);
   if (!asyncStream) {
     return NS_NewBufferedInputStream(aSyncStream, aAsyncStream, 4096);
   }
 
   uint64_t length;
   nsresult rv = aAsyncStream->Available(&length);
+  if (rv == NS_BASE_STREAM_CLOSED) {
+    // The stream has already been closed. Nothing to do.
+    *aSyncStream = nullptr;
+    return NS_OK;
+  }
+
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   nsAutoCString buffer;
   if (!buffer.SetLength(length, fallible)) {
     return NS_ERROR_OUT_OF_MEMORY;
   }