Bug 1415081 - part 5 - Fix the use of NS_ReadInputStreamToString in nsFrameMessageManager, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 09 Nov 2017 11:18:09 +0100
changeset 444207 b9d2a4a48001d94a073f800934b17b525eb87e7d
parent 444206 872fbd19734644c1a26851feb658d7078902d604
child 444208 f4bd7673388052dafc246fb960421c2b900c335a
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1415081
milestone58.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 1415081 - part 5 - Fix the use of NS_ReadInputStreamToString in nsFrameMessageManager, r=smaug
dom/base/nsFrameMessageManager.cpp
--- a/dom/base/nsFrameMessageManager.cpp
+++ b/dom/base/nsFrameMessageManager.cpp
@@ -1624,27 +1624,25 @@ nsMessageManagerScriptExecutor::TryCache
     }
 
     nsCOMPtr<nsIInputStream> input;
     rv = channel->Open2(getter_AddRefs(input));
     NS_ENSURE_SUCCESS_VOID(rv);
     nsString dataString;
     char16_t* dataStringBuf = nullptr;
     size_t dataStringLength = 0;
-    uint64_t avail64 = 0;
-    if (input && NS_SUCCEEDED(input->Available(&avail64)) && avail64) {
-      if (avail64 > UINT32_MAX) {
+    if (input) {
+      nsCString buffer;
+      uint64_t written;
+      if (NS_FAILED(NS_ReadInputStreamToString(input, buffer, -1, &written))) {
         return;
       }
-      nsCString buffer;
-      uint32_t avail = (uint32_t)std::min(avail64, (uint64_t)UINT32_MAX);
-      if (NS_FAILED(NS_ReadInputStreamToString(input, buffer, avail))) {
-        return;
-      }
-      ScriptLoader::ConvertToUTF16(channel, (uint8_t*)buffer.get(), avail,
+
+      uint32_t size = (uint32_t)std::min(written, (uint64_t)UINT32_MAX);
+      ScriptLoader::ConvertToUTF16(channel, (uint8_t*)buffer.get(), size,
                                    EmptyString(), nullptr,
                                    dataStringBuf, dataStringLength);
     }
 
     JS::SourceBufferHolder srcBuf(dataStringBuf, dataStringLength,
                                   JS::SourceBufferHolder::GiveOwnership);
 
     if (!dataStringBuf || dataStringLength == 0) {