Bug 1415508 - use Span in constructing a byte input stream; r=mayhemer
authorAlex Gaynor <agaynor@mozilla.com>
Mon, 25 Feb 2019 19:11:20 +0000
changeset 518838 7bffd747d54adf39be339cfac01d785e4654ea55
parent 518837 4613c00d3163dac8523877feeed7a661efd9510b
child 518839 7a20c79a0e1236116417ef0b317e065f4e274b9f
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer
bugs1415508
milestone67.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 1415508 - use Span in constructing a byte input stream; r=mayhemer Differential Revision: https://phabricator.services.mozilla.com/D20687
dom/base/DOMParser.cpp
dom/events/DataTransfer.cpp
dom/fetch/BodyExtractor.cpp
dom/file/MemoryBlobImpl.cpp
dom/jsurl/nsJSProtocolHandler.cpp
dom/xhr/XMLHttpRequestMainThread.cpp
gfx/thebes/gfxSVGGlyphs.cpp
image/imgTools.cpp
modules/libjar/zipwriter/nsDeflateConverter.cpp
modules/libjar/zipwriter/nsZipDataStream.cpp
netwerk/protocol/ftp/FTPChannelChild.cpp
netwerk/protocol/ftp/FTPChannelParent.cpp
netwerk/protocol/http/HttpChannelChild.cpp
netwerk/protocol/http/HttpChannelParent.cpp
netwerk/protocol/http/nsHttpTransaction.cpp
netwerk/protocol/wyciwyg/WyciwygChannelChild.cpp
security/manager/ssl/nsNSSCallbacks.cpp
startupcache/StartupCacheUtils.cpp
toolkit/components/extensions/webrequest/StreamFilterParent.cpp
toolkit/components/places/FaviconHelpers.cpp
tools/fuzzing/interface/FuzzingInterfaceStream.h
uriloader/exthandler/ExternalHelperAppParent.cpp
widget/cocoa/nsClipboard.mm
widget/gtk/nsClipboard.cpp
xpcom/io/nsStringStream.cpp
xpcom/io/nsStringStream.h
xpcom/tests/gtest/TestSnappyStreams.cpp
--- a/dom/base/DOMParser.cpp
+++ b/dom/base/DOMParser.cpp
@@ -82,18 +82,18 @@ already_AddRefed<Document> DOMParser::Pa
   // Convert from UTF16 to UTF8 using fallible allocations
   if (!AppendUTF16toUTF8(aStr, utf8str, mozilla::fallible)) {
     aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
     return nullptr;
   }
 
   // The new stream holds a reference to the buffer
   nsCOMPtr<nsIInputStream> stream;
-  nsresult rv = NS_NewByteInputStream(getter_AddRefs(stream), utf8str.get(),
-                                      utf8str.Length(), NS_ASSIGNMENT_DEPEND);
+  nsresult rv = NS_NewByteInputStream(getter_AddRefs(stream), utf8str,
+                                      NS_ASSIGNMENT_DEPEND);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     aRv.Throw(rv);
     return nullptr;
   }
 
   return ParseFromStream(stream, NS_LITERAL_STRING("UTF-8"), utf8str.Length(),
                          aType, aRv);
 }
@@ -106,18 +106,19 @@ already_AddRefed<Document> DOMParser::Pa
 }
 
 already_AddRefed<Document> DOMParser::ParseFromBuffer(Span<const uint8_t> aBuf,
                                                       SupportedType aType,
                                                       ErrorResult& aRv) {
   // The new stream holds a reference to the buffer
   nsCOMPtr<nsIInputStream> stream;
   nsresult rv = NS_NewByteInputStream(
-      getter_AddRefs(stream), reinterpret_cast<const char*>(aBuf.Elements()),
-      aBuf.Length(), NS_ASSIGNMENT_DEPEND);
+      getter_AddRefs(stream),
+      MakeSpan(reinterpret_cast<const char*>(aBuf.Elements()), aBuf.Length()),
+      NS_ASSIGNMENT_DEPEND);
   if (NS_FAILED(rv)) {
     aRv.Throw(rv);
     return nullptr;
   }
 
   return ParseFromStream(stream, VoidString(), aBuf.Length(), aType, aRv);
 }
 
--- a/dom/events/DataTransfer.cpp
+++ b/dom/events/DataTransfer.cpp
@@ -1503,17 +1503,18 @@ void DataTransfer::FillInExternalCustomT
   }
 
   CheckedInt<int32_t> checkedLen(len);
   if (!checkedLen.isValid()) {
     return;
   }
 
   nsCOMPtr<nsIInputStream> stringStream;
-  NS_NewByteInputStream(getter_AddRefs(stringStream), chrs, checkedLen.value(),
+  NS_NewByteInputStream(getter_AddRefs(stringStream),
+                        MakeSpan(chrs, checkedLen.value()),
                         NS_ASSIGNMENT_ADOPT);
 
   nsCOMPtr<nsIObjectInputStream> stream = NS_NewObjectInputStream(stringStream);
 
   uint32_t type;
   do {
     rv = stream->Read32(&type);
     NS_ENSURE_SUCCESS_VOID(rv);
--- a/dom/fetch/BodyExtractor.cpp
+++ b/dom/fetch/BodyExtractor.cpp
@@ -27,18 +27,18 @@ static nsresult GetBufferDataAsStream(
     uint64_t* aContentLength, nsACString& aContentType, nsACString& aCharset) {
   aContentType.SetIsVoid(true);
   aCharset.Truncate();
 
   *aContentLength = aDataLength;
   const char* data = reinterpret_cast<const char*>(aData);
 
   nsCOMPtr<nsIInputStream> stream;
-  nsresult rv = NS_NewByteInputStream(getter_AddRefs(stream), data, aDataLength,
-                                      NS_ASSIGNMENT_COPY);
+  nsresult rv = NS_NewByteInputStream(
+      getter_AddRefs(stream), MakeSpan(data, aDataLength), NS_ASSIGNMENT_COPY);
   NS_ENSURE_SUCCESS(rv, rv);
 
   stream.forget(aResult);
 
   return NS_OK;
 }
 
 template <>
--- a/dom/file/MemoryBlobImpl.cpp
+++ b/dom/file/MemoryBlobImpl.cpp
@@ -31,17 +31,17 @@ nsresult MemoryBlobImpl::DataOwnerAdapte
                                                   nsIInputStream** _retval) {
   nsresult rv;
   MOZ_ASSERT(aDataOwner, "Uh ...");
 
   nsCOMPtr<nsIInputStream> stream;
 
   rv = NS_NewByteInputStream(
       getter_AddRefs(stream),
-      static_cast<const char*>(aDataOwner->mData) + aStart, (int32_t)aLength,
+      MakeSpan(static_cast<const char*>(aDataOwner->mData) + aStart, aLength),
       NS_ASSIGNMENT_DEPEND);
   NS_ENSURE_SUCCESS(rv, rv);
 
   NS_ADDREF(*_retval =
                 new MemoryBlobImpl::DataOwnerAdapter(aDataOwner, stream));
 
   return NS_OK;
 }
--- a/dom/jsurl/nsJSProtocolHandler.cpp
+++ b/dom/jsurl/nsJSProtocolHandler.cpp
@@ -284,17 +284,18 @@ nsresult nsJSThunk::EvaluateScript(
       bytesLen = result.Length();
       charset = &isoCharset;
     } else {
       bytes = ToNewUTF8String(result, &bytesLen);
       charset = &utf8Charset;
     }
     aChannel->SetContentCharset(*charset);
     if (bytes)
-      rv = NS_NewByteInputStream(getter_AddRefs(mInnerStream), bytes, bytesLen,
+      rv = NS_NewByteInputStream(getter_AddRefs(mInnerStream),
+                                 mozilla::MakeSpan(bytes, bytesLen),
                                  NS_ASSIGNMENT_ADOPT);
     else
       rv = NS_ERROR_OUT_OF_MEMORY;
   }
 
   return rv;
 }
 
--- a/dom/xhr/XMLHttpRequestMainThread.cpp
+++ b/dom/xhr/XMLHttpRequestMainThread.cpp
@@ -1537,18 +1537,18 @@ nsresult XMLHttpRequestMainThread::Strea
 
   if (xmlHttpRequest->mFlagParseBody) {
     // Give the same data to the parser.
 
     // We need to wrap the data in a new lightweight stream and pass that
     // to the parser, because calling ReadSegments() recursively on the same
     // stream is not supported.
     nsCOMPtr<nsIInputStream> copyStream;
-    rv = NS_NewByteInputStream(getter_AddRefs(copyStream), fromRawSegment,
-                               count);
+    rv = NS_NewByteInputStream(getter_AddRefs(copyStream),
+                               MakeSpan(fromRawSegment, count));
 
     if (NS_SUCCEEDED(rv) && xmlHttpRequest->mXMLParserStreamListener) {
       NS_ASSERTION(copyStream, "NS_NewByteInputStream lied");
       nsresult parsingResult =
           xmlHttpRequest->mXMLParserStreamListener->OnDataAvailable(
               xmlHttpRequest->mChannel, xmlHttpRequest->mContext, copyStream,
               toOffset, count);
 
--- a/gfx/thebes/gfxSVGGlyphs.cpp
+++ b/gfx/thebes/gfxSVGGlyphs.cpp
@@ -288,19 +288,20 @@ gfxSVGGlyphsDocument::~gfxSVGGlyphsDocum
     mViewer->Close(nullptr);
     mViewer->Destroy();
   }
 }
 
 static nsresult CreateBufferedStream(const uint8_t *aBuffer, uint32_t aBufLen,
                                      nsCOMPtr<nsIInputStream> &aResult) {
   nsCOMPtr<nsIInputStream> stream;
-  nsresult rv = NS_NewByteInputStream(getter_AddRefs(stream),
-                                      reinterpret_cast<const char *>(aBuffer),
-                                      aBufLen, NS_ASSIGNMENT_DEPEND);
+  nsresult rv = NS_NewByteInputStream(
+      getter_AddRefs(stream),
+      MakeSpan(reinterpret_cast<const char *>(aBuffer), aBufLen),
+      NS_ASSIGNMENT_DEPEND);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIInputStream> aBufferedStream;
   if (!NS_InputStreamIsBuffered(stream)) {
     rv = NS_NewBufferedInputStream(getter_AddRefs(aBufferedStream),
                                    stream.forget(), 4096);
     NS_ENSURE_SUCCESS(rv, rv);
     stream = aBufferedStream;
--- a/image/imgTools.cpp
+++ b/image/imgTools.cpp
@@ -208,18 +208,18 @@ imgTools::DecodeImageFromBuffer(const ch
   RefPtr<ProgressTracker> tracker = image->GetProgressTracker();
 
   if (image->HasError()) {
     return NS_ERROR_FAILURE;
   }
 
   // Let's create a temporary inputStream.
   nsCOMPtr<nsIInputStream> stream;
-  nsresult rv = NS_NewByteInputStream(getter_AddRefs(stream), aBuffer, aSize,
-                                      NS_ASSIGNMENT_DEPEND);
+  nsresult rv = NS_NewByteInputStream(
+      getter_AddRefs(stream), MakeSpan(aBuffer, aSize), NS_ASSIGNMENT_DEPEND);
   NS_ENSURE_SUCCESS(rv, rv);
   MOZ_ASSERT(stream);
   MOZ_ASSERT(NS_InputStreamIsBuffered(stream));
 
   rv = image->OnImageDataAvailable(nullptr, nullptr, stream, 0, aSize);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Let the Image know we've sent all the data.
--- a/modules/libjar/zipwriter/nsDeflateConverter.cpp
+++ b/modules/libjar/zipwriter/nsDeflateConverter.cpp
@@ -154,18 +154,18 @@ NS_IMETHODIMP nsDeflateConverter::OnStop
 nsresult nsDeflateConverter::PushAvailableData(nsIRequest *aRequest,
                                                nsISupports *aContext) {
   uint32_t bytesToWrite = sizeof(mWriteBuffer) - mZstream.avail_out;
   // We don't need to do anything if there isn't any data
   if (bytesToWrite == 0) return NS_OK;
 
   MOZ_ASSERT(bytesToWrite <= INT32_MAX);
   nsCOMPtr<nsIInputStream> stream;
-  nsresult rv = NS_NewByteInputStream(getter_AddRefs(stream),
-                                      (char *)mWriteBuffer, bytesToWrite);
+  nsresult rv = NS_NewByteInputStream(
+      getter_AddRefs(stream), MakeSpan((char *)mWriteBuffer, bytesToWrite));
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = mListener->OnDataAvailable(aRequest, mContext, stream, mOffset,
                                   bytesToWrite);
 
   // now set the state for 'deflate'
   mZstream.next_out = mWriteBuffer;
   mZstream.avail_out = sizeof(mWriteBuffer);
--- a/modules/libjar/zipwriter/nsZipDataStream.cpp
+++ b/modules/libjar/zipwriter/nsZipDataStream.cpp
@@ -115,17 +115,18 @@ inline nsresult nsZipDataStream::Complet
 nsresult nsZipDataStream::ProcessData(nsIRequest *aRequest,
                                       nsISupports *aContext, char *aBuffer,
                                       uint64_t aOffset, uint32_t aCount) {
   mHeader->mCRC = crc32(
       mHeader->mCRC, reinterpret_cast<const unsigned char *>(aBuffer), aCount);
 
   MOZ_ASSERT(aCount <= INT32_MAX);
   nsCOMPtr<nsIInputStream> stream;
-  nsresult rv = NS_NewByteInputStream(getter_AddRefs(stream), aBuffer, aCount);
+  nsresult rv =
+      NS_NewByteInputStream(getter_AddRefs(stream), MakeSpan(aBuffer, aCount));
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = mOutput->OnDataAvailable(aRequest, aContext, stream, aOffset, aCount);
   mHeader->mUSize += aCount;
 
   return rv;
 }
 
--- a/netwerk/protocol/ftp/FTPChannelChild.cpp
+++ b/netwerk/protocol/ftp/FTPChannelChild.cpp
@@ -417,18 +417,19 @@ void FTPChannelChild::DoOnDataAvailable(
   }
 
   // NOTE: the OnDataAvailable contract requires the client to read all the data
   // in the inputstream.  This code relies on that ('data' will go away after
   // this function).  Apparently the previous, non-e10s behavior was to actually
   // support only reading part of the data, allowing later calls to read the
   // rest.
   nsCOMPtr<nsIInputStream> stringStream;
-  nsresult rv = NS_NewByteInputStream(getter_AddRefs(stringStream), data.get(),
-                                      count, NS_ASSIGNMENT_DEPEND);
+  nsresult rv =
+      NS_NewByteInputStream(getter_AddRefs(stringStream),
+                            MakeSpan(data).To(count), NS_ASSIGNMENT_DEPEND);
   if (NS_FAILED(rv)) {
     Cancel(rv);
     return;
   }
 
   AutoEventEnqueuer ensureSerialDispatch(mEventQ);
   rv = mListener->OnDataAvailable(this, nullptr, stringStream, offset, count);
   if (NS_FAILED(rv)) Cancel(rv);
--- a/netwerk/protocol/ftp/FTPChannelParent.cpp
+++ b/netwerk/protocol/ftp/FTPChannelParent.cpp
@@ -255,18 +255,19 @@ void FTPChannelParent::DivertOnDataAvail
   }
 
   // Drop OnDataAvailables if the parent was canceled already.
   if (NS_FAILED(mStatus)) {
     return;
   }
 
   nsCOMPtr<nsIInputStream> stringStream;
-  nsresult rv = NS_NewByteInputStream(getter_AddRefs(stringStream), data.get(),
-                                      count, NS_ASSIGNMENT_DEPEND);
+  nsresult rv =
+      NS_NewByteInputStream(getter_AddRefs(stringStream),
+                            MakeSpan(data).To(count), NS_ASSIGNMENT_DEPEND);
   if (NS_FAILED(rv)) {
     if (mChannel) {
       mChannel->Cancel(rv);
     }
     mStatus = rv;
     return;
   }
 
--- a/netwerk/protocol/http/HttpChannelChild.cpp
+++ b/netwerk/protocol/http/HttpChannelChild.cpp
@@ -842,18 +842,19 @@ void HttpChannelChild::OnTransportAndDat
   // OnDataAvailable
   //
   // NOTE: the OnDataAvailable contract requires the client to read all the data
   // in the inputstream.  This code relies on that ('data' will go away after
   // this function).  Apparently the previous, non-e10s behavior was to actually
   // support only reading part of the data, allowing later calls to read the
   // rest.
   nsCOMPtr<nsIInputStream> stringStream;
-  nsresult rv = NS_NewByteInputStream(getter_AddRefs(stringStream), data.get(),
-                                      count, NS_ASSIGNMENT_DEPEND);
+  nsresult rv =
+      NS_NewByteInputStream(getter_AddRefs(stringStream),
+                            MakeSpan(data).To(count), NS_ASSIGNMENT_DEPEND);
   if (NS_FAILED(rv)) {
     Cancel(rv);
     return;
   }
 
   DoOnDataAvailable(this, nullptr, stringStream, offset, count);
   stringStream->Close();
 
--- a/netwerk/protocol/http/HttpChannelParent.cpp
+++ b/netwerk/protocol/http/HttpChannelParent.cpp
@@ -1073,18 +1073,19 @@ void HttpChannelParent::DivertOnDataAvai
   }
 
   // Drop OnDataAvailables if the parent was canceled already.
   if (NS_FAILED(mStatus)) {
     return;
   }
 
   nsCOMPtr<nsIInputStream> stringStream;
-  nsresult rv = NS_NewByteInputStream(getter_AddRefs(stringStream), data.get(),
-                                      count, NS_ASSIGNMENT_DEPEND);
+  nsresult rv =
+      NS_NewByteInputStream(getter_AddRefs(stringStream),
+                            MakeSpan(data).To(count), NS_ASSIGNMENT_DEPEND);
   if (NS_FAILED(rv)) {
     if (mChannel) {
       mChannel->Cancel(rv);
     }
     mStatus = rv;
     return;
   }
 
--- a/netwerk/protocol/http/nsHttpTransaction.cpp
+++ b/netwerk/protocol/http/nsHttpTransaction.cpp
@@ -373,18 +373,17 @@ nsresult nsHttpTransaction::Init(
       LOG3(("ObserveActivity failed (%08x)", static_cast<uint32_t>(rv)));
     }
   }
 
   // Create a string stream for the request header buf (the stream holds
   // a non-owning reference to the request header data, so we MUST keep
   // mReqHeaderBuf around).
   nsCOMPtr<nsIInputStream> headers;
-  rv = NS_NewByteInputStream(getter_AddRefs(headers), mReqHeaderBuf.get(),
-                             mReqHeaderBuf.Length());
+  rv = NS_NewByteInputStream(getter_AddRefs(headers), mReqHeaderBuf);
   if (NS_FAILED(rv)) return rv;
 
   mHasRequestBody = !!requestBody;
   if (mHasRequestBody && !requestContentLength) {
     mHasRequestBody = false;
   }
 
   requestContentLength += mReqHeaderBuf.Length();
--- a/netwerk/protocol/wyciwyg/WyciwygChannelChild.cpp
+++ b/netwerk/protocol/wyciwyg/WyciwygChannelChild.cpp
@@ -220,18 +220,18 @@ void WyciwygChannelChild::OnDataAvailabl
   mState = WCC_ONDATA;
 
   // NOTE: the OnDataAvailable contract requires the client to read all the data
   // in the inputstream.  This code relies on that ('data' will go away after
   // this function).  Apparently the previous, non-e10s behavior was to actually
   // support only reading part of the data, allowing later calls to read the
   // rest.
   nsCOMPtr<nsIInputStream> stringStream;
-  nsresult rv = NS_NewByteInputStream(getter_AddRefs(stringStream), data.get(),
-                                      data.Length(), NS_ASSIGNMENT_DEPEND);
+  nsresult rv = NS_NewByteInputStream(getter_AddRefs(stringStream), data,
+                                      NS_ASSIGNMENT_DEPEND);
   if (NS_FAILED(rv)) {
     Cancel(rv);
     return;
   }
 
   AutoEventEnqueuer ensureSerialDispatch(mEventQ);
 
   rv = mListener->OnDataAvailable(this, nullptr, stringStream, offset,
--- a/security/manager/ssl/nsNSSCallbacks.cpp
+++ b/security/manager/ssl/nsNSSCallbacks.cpp
@@ -274,19 +274,20 @@ OCSPRequest::Run() {
     nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
     rv = loadInfo->SetOriginAttributes(attrs);
     if (NS_FAILED(rv)) {
       return NotifyDone(rv, lock);
     }
   }
 
   nsCOMPtr<nsIInputStream> uploadStream;
-  rv = NS_NewByteInputStream(getter_AddRefs(uploadStream),
-                             reinterpret_cast<const char*>(mPOSTData.begin()),
-                             mPOSTData.length());
+  rv = NS_NewByteInputStream(
+      getter_AddRefs(uploadStream),
+      MakeSpan(reinterpret_cast<const char*>(mPOSTData.begin()),
+               mPOSTData.length()));
   if (NS_FAILED(rv)) {
     return NotifyDone(rv, lock);
   }
   nsCOMPtr<nsIUploadChannel> uploadChannel(do_QueryInterface(channel));
   if (!uploadChannel) {
     return NotifyDone(NS_ERROR_FAILURE, lock);
   }
   rv = uploadChannel->SetUploadStream(uploadStream, OCSP_REQUEST_MIME_TYPE, -1);
--- a/startupcache/StartupCacheUtils.cpp
+++ b/startupcache/StartupCacheUtils.cpp
@@ -17,18 +17,19 @@
 #include "mozilla/Omnijar.h"
 
 namespace mozilla {
 namespace scache {
 
 nsresult NewObjectInputStreamFromBuffer(UniquePtr<char[]> buffer, uint32_t len,
                                         nsIObjectInputStream **stream) {
   nsCOMPtr<nsIInputStream> stringStream;
-  nsresult rv = NS_NewByteInputStream(
-      getter_AddRefs(stringStream), buffer.release(), len, NS_ASSIGNMENT_ADOPT);
+  nsresult rv = NS_NewByteInputStream(getter_AddRefs(stringStream),
+                                      MakeSpan(buffer.release(), len),
+                                      NS_ASSIGNMENT_ADOPT);
   MOZ_ALWAYS_SUCCEEDS(rv);
 
   nsCOMPtr<nsIObjectInputStream> objectInput =
       NS_NewObjectInputStream(stringStream);
 
   objectInput.forget(stream);
   return NS_OK;
 }
--- a/toolkit/components/extensions/webrequest/StreamFilterParent.cpp
+++ b/toolkit/components/extensions/webrequest/StreamFilterParent.cpp
@@ -353,19 +353,19 @@ void StreamFilterParent::WriteMove(Data&
   nsresult rv = Write(aData);
   Unused << NS_WARN_IF(NS_FAILED(rv));
 }
 
 nsresult StreamFilterParent::Write(Data& aData) {
   AssertIsIOThread();
 
   nsCOMPtr<nsIInputStream> stream;
-  nsresult rv = NS_NewByteInputStream(getter_AddRefs(stream),
-                                      reinterpret_cast<char*>(aData.Elements()),
-                                      aData.Length());
+  nsresult rv = NS_NewByteInputStream(
+      getter_AddRefs(stream),
+      MakeSpan(reinterpret_cast<char*>(aData.Elements()), aData.Length()));
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = mOrigListener->OnDataAvailable(mChannel, mContext, stream, mOffset,
                                       aData.Length());
   NS_ENSURE_SUCCESS(rv, rv);
 
   mOffset += aData.Length();
   return NS_OK;
--- a/toolkit/components/places/FaviconHelpers.cpp
+++ b/toolkit/components/places/FaviconHelpers.cpp
@@ -1219,18 +1219,18 @@ nsresult FetchAndConvertUnsupportedPaylo
   // If it's an SVG, there's nothing to optimize or convert.
   if (aMimeType.EqualsLiteral(SVG_MIME_TYPE)) {
     *aWidth = UINT16_MAX;
     return NS_OK;
   }
 
   // Convert the payload to an input stream.
   nsCOMPtr<nsIInputStream> stream;
-  nsresult rv = NS_NewByteInputStream(getter_AddRefs(stream), aPayload.get(),
-                                      aPayload.Length(), NS_ASSIGNMENT_DEPEND);
+  nsresult rv = NS_NewByteInputStream(getter_AddRefs(stream), aPayload,
+                                      NS_ASSIGNMENT_DEPEND);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Decode the input stream to a surface.
   RefPtr<gfx::SourceSurface> surface = image::ImageOps::DecodeToSurface(
       stream.forget(), aMimeType, imgIContainer::DECODE_FLAGS_DEFAULT);
   NS_ENSURE_STATE(surface);
   RefPtr<gfx::DataSourceSurface> dataSurface = surface->GetDataSurface();
   NS_ENSURE_STATE(dataSurface);
--- a/tools/fuzzing/interface/FuzzingInterfaceStream.h
+++ b/tools/fuzzing/interface/FuzzingInterfaceStream.h
@@ -61,19 +61,19 @@ void afl_interface_stream(const char* te
                                                                     */
 #endif
 
 #ifdef LIBFUZZER
 #  define MOZ_LIBFUZZER_INTERFACE_STREAM(initFunc, testFunc, moduleName)     \
     static int LibFuzzerTest##moduleName(const uint8_t* data, size_t size) { \
       if (size > INT32_MAX) return 0;                                        \
       nsCOMPtr<nsIInputStream> stream;                                       \
-      nsresult rv =                                                          \
-          NS_NewByteInputStream(getter_AddRefs(stream), (const char*)data,   \
-                                size, NS_ASSIGNMENT_DEPEND);                 \
+      nsresult rv = NS_NewByteInputStream(getter_AddRefs(stream),            \
+                                          MakeSpan((const char*)data, size), \
+                                          NS_ASSIGNMENT_DEPEND);             \
       MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));                                  \
       testFunc(stream.forget());                                             \
       return 0;                                                              \
     }                                                                        \
     static void __attribute__((constructor)) LibFuzzerRegister() {           \
       ::mozilla::FuzzerRegistry::getInstance().registerModule(               \
           #moduleName, initFunc, LibFuzzerTest##moduleName);                 \
     }
--- a/uriloader/exthandler/ExternalHelperAppParent.cpp
+++ b/uriloader/exthandler/ExternalHelperAppParent.cpp
@@ -146,18 +146,19 @@ mozilla::ipc::IPCResult ExternalHelperAp
     const nsCString& data, const uint64_t& offset, const uint32_t& count) {
   if (NS_FAILED(mStatus)) return IPC_OK();
 
   MOZ_ASSERT(!mDiverted,
              "child forwarding callbacks after request was diverted");
   MOZ_ASSERT(mPending, "must be pending!");
 
   nsCOMPtr<nsIInputStream> stringStream;
-  DebugOnly<nsresult> rv = NS_NewByteInputStream(
-      getter_AddRefs(stringStream), data.get(), count, NS_ASSIGNMENT_DEPEND);
+  DebugOnly<nsresult> rv =
+      NS_NewByteInputStream(getter_AddRefs(stringStream),
+                            MakeSpan(data).To(count), NS_ASSIGNMENT_DEPEND);
   NS_ASSERTION(NS_SUCCEEDED(rv), "failed to create dependent string!");
   mStatus =
       mListener->OnDataAvailable(this, nullptr, stringStream, offset, count);
 
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult ExternalHelperAppParent::RecvOnStopRequest(
--- a/widget/cocoa/nsClipboard.mm
+++ b/widget/cocoa/nsClipboard.mm
@@ -282,18 +282,20 @@ nsresult nsClipboard::TransferableFromPa
       CGImageDestinationRef dest =
           CGImageDestinationCreateWithData((CFMutableDataRef)encodedData, outputType, 1, NULL);
       CGImageDestinationAddImageFromSource(dest, source, 0, NULL);
       bool successfullyConverted = CGImageDestinationFinalize(dest);
 
       if (successfullyConverted) {
         // Put the converted data in a form Gecko can understand
         nsCOMPtr<nsIInputStream> byteStream;
-        NS_NewByteInputStream(getter_AddRefs(byteStream), (const char*)[encodedData bytes],
-                              [encodedData length], NS_ASSIGNMENT_COPY);
+        NS_NewByteInputStream(
+            getter_AddRefs(byteStream),
+            mozilla::MakeSpan((const char*)[encodedData bytes], [encodedData length]),
+            NS_ASSIGNMENT_COPY);
 
         aTransferable->SetTransferData(flavorStr.get(), byteStream);
       }
 
       if (dest) CFRelease(dest);
       if (source) CFRelease(source);
 
       if (successfullyConverted)
--- a/widget/gtk/nsClipboard.cpp
+++ b/widget/gtk/nsClipboard.cpp
@@ -239,18 +239,19 @@ nsClipboard::GetData(nsITransferable *aT
       }
 
       uint32_t clipboardDataLength;
       const char *clipboardData = mContext->GetClipboardData(
           flavorStr.get(), aWhichClipboard, &clipboardDataLength);
       if (!clipboardData) continue;
 
       nsCOMPtr<nsIInputStream> byteStream;
-      NS_NewByteInputStream(getter_AddRefs(byteStream), clipboardData,
-                            clipboardDataLength, NS_ASSIGNMENT_COPY);
+      NS_NewByteInputStream(getter_AddRefs(byteStream),
+                            MakeSpan(clipboardData, clipboardDataLength),
+                            NS_ASSIGNMENT_COPY);
       aTransferable->SetTransferData(flavorStr.get(), byteStream);
 
       mContext->ReleaseClipboardData(clipboardData);
       return NS_OK;
     }
 
     // Special case text/unicode since we can convert any
     // string into text/unicode
--- a/xpcom/io/nsStringStream.cpp
+++ b/xpcom/io/nsStringStream.cpp
@@ -439,32 +439,33 @@ nsStringInputStream::Clone(nsIInputStrea
   // mOffset is overwritten by SetData().
   ref->mOffset = mOffset;
 
   ref.forget(aCloneOut);
   return NS_OK;
 }
 
 nsresult NS_NewByteInputStream(nsIInputStream** aStreamResult,
-                               const char* aStringToRead, int32_t aLength,
+                               Span<const char> aStringToRead,
                                nsAssignmentType aAssignment) {
   MOZ_ASSERT(aStreamResult, "null out ptr");
 
   RefPtr<nsStringInputStream> stream = new nsStringInputStream();
 
   nsresult rv;
   switch (aAssignment) {
     case NS_ASSIGNMENT_COPY:
-      rv = stream->SetData(aStringToRead, aLength);
+      rv = stream->SetData(aStringToRead.Elements(), aStringToRead.Length());
       break;
     case NS_ASSIGNMENT_DEPEND:
-      rv = stream->ShareData(aStringToRead, aLength);
+      rv = stream->ShareData(aStringToRead.Elements(), aStringToRead.Length());
       break;
     case NS_ASSIGNMENT_ADOPT:
-      rv = stream->AdoptData(const_cast<char*>(aStringToRead), aLength);
+      rv = stream->AdoptData(const_cast<char*>(aStringToRead.Elements()),
+                             aStringToRead.Length());
       break;
     default:
       NS_ERROR("invalid assignment type");
       rv = NS_ERROR_INVALID_ARG;
   }
 
   if (NS_FAILED(rv)) {
     return rv;
--- a/xpcom/io/nsStringStream.h
+++ b/xpcom/io/nsStringStream.h
@@ -43,18 +43,18 @@
  * If aAssignment is NS_ASSIGNMENT_ADOPT, then the resulting stream refers
  * directly to the given buffer (aStringToRead) and will free aStringToRead
  * once the stream is closed.
  *
  * If aLength is less than zero, then the length of aStringToRead will be
  * determined by scanning the buffer for the first null byte.
  */
 extern nsresult NS_NewByteInputStream(
-    nsIInputStream** aStreamResult, const char* aStringToRead,
-    int32_t aLength = -1, nsAssignmentType aAssignment = NS_ASSIGNMENT_DEPEND);
+    nsIInputStream** aStreamResult, mozilla::Span<const char> aStringToRead,
+    nsAssignmentType aAssignment = NS_ASSIGNMENT_DEPEND);
 
 /**
  * Factory method to get an nsInputStream from an nsACString.  Result will
  * implement nsIStringInputStream, nsTellableStream and nsISeekableStream.
  */
 extern nsresult NS_NewCStringInputStream(nsIInputStream** aStreamResult,
                                          const nsACString& aStringToRead);
 extern nsresult NS_NewCStringInputStream(nsIInputStream** aStreamResult,
--- a/xpcom/tests/gtest/TestSnappyStreams.cpp
+++ b/xpcom/tests/gtest/TestSnappyStreams.cpp
@@ -79,18 +79,18 @@ static void TestCompressUncompress(uint3
   for (uint32_t i = 0; i < inputData.Length(); ++i) {
     EXPECT_EQ(inputData[i], outputData.get()[i]) << "Byte " << i;
   }
 }
 
 static void TestUncompressCorrupt(const char* aCorruptData,
                                   uint32_t aCorruptLength) {
   nsCOMPtr<nsIInputStream> source;
-  nsresult rv = NS_NewByteInputStream(getter_AddRefs(source), aCorruptData,
-                                      aCorruptLength);
+  nsresult rv = NS_NewByteInputStream(getter_AddRefs(source),
+                                      MakeSpan(aCorruptData, aCorruptLength));
   ASSERT_TRUE(NS_SUCCEEDED(rv));
 
   nsCOMPtr<nsIInputStream> uncompress = new SnappyUncompressInputStream(source);
 
   nsAutoCString outputData;
   rv = NS_ConsumeStream(uncompress, UINT32_MAX, outputData);
   ASSERT_EQ(NS_ERROR_CORRUPTED_CONTENT, rv);
 }