Bug 1415508 - use Span in constructing a byte input stream; r=mayhemer

Differential Revision: https://phabricator.services.mozilla.com/D20687

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Alex Gaynor 2019-02-25 19:11:20 +00:00
Родитель 01800513e9
Коммит 0e903787da
27 изменённых файлов: 73 добавлений и 58 удалений

Просмотреть файл

@ -87,8 +87,8 @@ already_AddRefed<Document> DOMParser::ParseFromString(const nsAString& aStr,
// 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;
@ -111,8 +111,9 @@ already_AddRefed<Document> DOMParser::ParseFromBuffer(Span<const uint8_t> aBuf,
// 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;

Просмотреть файл

@ -1508,7 +1508,8 @@ void DataTransfer::FillInExternalCustomTypes(nsIVariant* aData, uint32_t aIndex,
}
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);

Просмотреть файл

@ -32,8 +32,8 @@ static nsresult GetBufferDataAsStream(
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);

Просмотреть файл

@ -36,7 +36,7 @@ nsresult MemoryBlobImpl::DataOwnerAdapter::Create(DataOwner* aDataOwner,
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);

Просмотреть файл

@ -289,7 +289,8 @@ nsresult nsJSThunk::EvaluateScript(
}
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;

Просмотреть файл

@ -1542,8 +1542,8 @@ nsresult XMLHttpRequestMainThread::StreamReaderFunc(
// 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");

Просмотреть файл

@ -293,9 +293,10 @@ gfxSVGGlyphsDocument::~gfxSVGGlyphsDocument() {
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;

Просмотреть файл

@ -213,8 +213,8 @@ imgTools::DecodeImageFromBuffer(const char* aBuffer, uint32_t aSize,
// 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));

Просмотреть файл

@ -159,8 +159,8 @@ nsresult nsDeflateConverter::PushAvailableData(nsIRequest *aRequest,
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,

Просмотреть файл

@ -120,7 +120,8 @@ nsresult nsZipDataStream::ProcessData(nsIRequest *aRequest,
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);

Просмотреть файл

@ -422,8 +422,9 @@ void FTPChannelChild::DoOnDataAvailable(const nsresult& channelStatus,
// 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;

Просмотреть файл

@ -260,8 +260,9 @@ void FTPChannelParent::DivertOnDataAvailable(const nsCString& data,
}
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);

Просмотреть файл

@ -847,8 +847,9 @@ void HttpChannelChild::OnTransportAndData(const nsresult& channelStatus,
// 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;

Просмотреть файл

@ -1078,8 +1078,9 @@ void HttpChannelParent::DivertOnDataAvailable(const nsCString& data,
}
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);

Просмотреть файл

@ -378,8 +378,7 @@ nsresult nsHttpTransaction::Init(
// 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;

Просмотреть файл

@ -225,8 +225,8 @@ void WyciwygChannelChild::OnDataAvailable(const nsCString& data,
// 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;

Просмотреть файл

@ -279,9 +279,10 @@ OCSPRequest::Run() {
}
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);
}

Просмотреть файл

@ -22,8 +22,9 @@ 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 =

Просмотреть файл

@ -358,9 +358,9 @@ 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,

Просмотреть файл

@ -1224,8 +1224,8 @@ nsresult FetchAndConvertUnsupportedPayloads::ConvertPayload(
// 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.

Просмотреть файл

@ -66,9 +66,9 @@ void afl_interface_stream(const char* testFile, FuzzingTestFuncStream testFunc);
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; \

Просмотреть файл

@ -151,8 +151,9 @@ mozilla::ipc::IPCResult ExternalHelperAppParent::RecvOnDataAvailable(
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);

Просмотреть файл

@ -287,8 +287,10 @@ nsresult nsClipboard::TransferableFromPasteboard(nsITransferable* aTransferable,
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);
}

Просмотреть файл

@ -244,8 +244,9 @@ nsClipboard::GetData(nsITransferable *aTransferable, int32_t aWhichClipboard) {
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);

Просмотреть файл

@ -444,7 +444,7 @@ nsStringInputStream::Clone(nsIInputStream** aCloneOut) {
}
nsresult NS_NewByteInputStream(nsIInputStream** aStreamResult,
const char* aStringToRead, int32_t aLength,
Span<const char> aStringToRead,
nsAssignmentType aAssignment) {
MOZ_ASSERT(aStreamResult, "null out ptr");
@ -453,13 +453,14 @@ nsresult NS_NewByteInputStream(nsIInputStream** aStreamResult,
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");

Просмотреть файл

@ -48,8 +48,8 @@
* 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

Просмотреть файл

@ -84,8 +84,8 @@ static void TestCompressUncompress(uint32_t aNumBytes) {
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);