Bug 1404045 - follow-up 2: Use SlicedInputStream() where offset/length for NS_NewInputStreamPump() are necessary. rs=bustage-fix
authorJorg K <jorgk@jorgk.com>
Sat, 30 Sep 2017 20:41:49 +0200
changeset 29070 3c0dde60442ecc04dd4af8b32593a764c494e950
parent 29069 b70a05002bb5741b8875600416aea2df03286f96
child 29071 079662f3683788017ec3c4f605863681c5e2d0e2
push id2068
push userclokep@gmail.com
push dateMon, 13 Nov 2017 19:02:14 +0000
treeherdercomm-beta@9c7e7ce8672b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbustage-fix
bugs1404045
Bug 1404045 - follow-up 2: Use SlicedInputStream() where offset/length for NS_NewInputStreamPump() are necessary. rs=bustage-fix
mailnews/base/util/nsMsgProtocol.cpp
--- a/mailnews/base/util/nsMsgProtocol.cpp
+++ b/mailnews/base/util/nsMsgProtocol.cpp
@@ -462,19 +462,26 @@ nsresult nsMsgProtocol::LoadUrl(nsIURI *
         // don't open the input stream more than once
         if (!m_inputStream)
         {
           // open buffered, asynchronous input stream
           rv = m_transport->OpenInputStream(0, 0, 0, getter_AddRefs(m_inputStream));
           if (NS_FAILED(rv)) return rv;
         }
 
+        int64_t offset = 0;
+        nsCOMPtr<nsISeekableStream> seekable(do_QueryInterface(m_inputStream));
+        if (seekable)
+          seekable->Tell(&offset);
+
+        // Note that SlicedInputStream() accepts uint64_t(-1)==UINT64_MAX for the length.
+        RefPtr<SlicedInputStream> slicedStream =
+          new SlicedInputStream(m_inputStream, uint64_t(offset), uint64_t(m_readCount));
         nsCOMPtr<nsIInputStreamPump> pump;
-        rv = NS_NewInputStreamPump(getter_AddRefs(pump),
-          m_inputStream, -1, m_readCount);
+        rv = NS_NewInputStreamPump(getter_AddRefs(pump), slicedStream);
         if (NS_FAILED(rv)) return rv;
 
         m_request = pump; // keep a reference to the pump so we can cancel it
 
         // put us in a state where we are always notified of incoming data
         rv = pump->AsyncRead(this, urlSupports);
         NS_ASSERTION(NS_SUCCEEDED(rv), "AsyncRead failed");
         m_socketIsOpen = true; // mark the channel as open