Bug 1332587 - FileReader cannot allocate more than INT32_MAX for an ArrayBuffer, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 20 Jan 2017 12:33:18 +0100
changeset 377620 9b5cc104aaf600a84643800a17bddfbed0acbc24
parent 377572 ae8caa5d668abfa77d4e041e783784b9eb0f76fc
child 377621 59962d7c3d8c00a6d774362deb0934e84b1938c6
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1332587
milestone53.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 1332587 - FileReader cannot allocate more than INT32_MAX for an ArrayBuffer, r=smaug
dom/file/FileReader.cpp
--- a/dom/file/FileReader.cpp
+++ b/dom/file/FileReader.cpp
@@ -409,16 +409,22 @@ FileReader::ReadFileContent(Blob& aBlob,
   MOZ_ASSERT(mAsyncStream);
 
   mTotal = mBlob->GetSize(aRv);
   if (NS_WARN_IF(aRv.Failed())) {
     return;
   }
 
   if (mDataFormat == FILE_AS_ARRAYBUFFER) {
+    // This limit comes from ArrayBufferObject::setByteLength.
+    if (mTotal > INT32_MAX) {
+      aRv.Throw(NS_ERROR_RANGE_ERR);
+      return;
+    }
+
     mFileData = js_pod_malloc<char>(mTotal);
     if (!mFileData) {
       NS_WARNING("Preallocation failed for ReadFileData");
       aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
       return;
     }
   }