Bug 1480354 - Better approach for nested blobs construction, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 03 Aug 2018 08:58:32 +0200
changeset 826238 3f58dc7309e39047199a848db90d9ce940308505
parent 826237 56cd87390012d2959066c06a33e968ffea544e07
child 826239 cd23a7207dbbec30a3d1682d678ed76d73a6248b
push id118275
push userbmo:dharvey@mozilla.com
push dateFri, 03 Aug 2018 11:44:33 +0000
reviewerssmaug
bugs1480354
milestone63.0a1
Bug 1480354 - Better approach for nested blobs construction, r=smaug
dom/file/BlobSet.cpp
dom/file/tests/crashtests/1480354.html
dom/file/tests/crashtests/crashtests.list
--- a/dom/file/BlobSet.cpp
+++ b/dom/file/BlobSet.cpp
@@ -54,16 +54,31 @@ BlobSet::AppendString(const nsAString& a
     StringBlobImpl::Create(utf8Str, EmptyString());
   return AppendBlobImpl(blobImpl);
 }
 
 nsresult
 BlobSet::AppendBlobImpl(BlobImpl* aBlobImpl)
 {
   NS_ENSURE_ARG_POINTER(aBlobImpl);
+
+  // If aBlobImpl is a MultipartBlobImpl, let's append the sub-blobImpls
+  // instead.
+  const nsTArray<RefPtr<BlobImpl>>* subBlobs = aBlobImpl->GetSubBlobImpls();
+  if (subBlobs) {
+    for (BlobImpl* subBlob : *subBlobs) {
+      nsresult rv = AppendBlobImpl(subBlob);
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
+    }
+
+    return NS_OK;
+  }
+
   if (NS_WARN_IF(!mBlobImpls.AppendElement(aBlobImpl, fallible))) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
   return NS_OK;
 }
 
 } // dom namespace
 } // mozilla namespace
new file mode 100644
--- /dev/null
+++ b/dom/file/tests/crashtests/1480354.html
@@ -0,0 +1,14 @@
+<html>
+<body>
+  <script>
+function createBlob(blocksize) {
+  var blob = new Blob();
+  while (blob.size < 25 * 1024 * 1024) { // 25 MB
+    blob = new Blob([blob, new Uint8Array(blocksize)]);
+  }
+  URL.createObjectURL(blob);
+}
+createBlob(1024 * 25);
+  </script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/file/tests/crashtests/crashtests.list
@@ -0,0 +1,1 @@
+load 1480354.html