Commit c0341c37 authored by Simon Giesecke's avatar Simon Giesecke
Browse files

Bug 1628715 - Part 10: Activate nodiscard attributes on AppendElement(s)....

Bug 1628715 - Part 10: Activate nodiscard attributes on AppendElement(s). r=xpcom-reviewers,nika,peterv

Differential Revision: https://phabricator.services.mozilla.com/D70834
parent 6d5ba855
......@@ -9,6 +9,7 @@
#include "TimelineMarker.h"
#include "mozilla/dom/ProfileTimelineMarkerBinding.h"
#include "mozilla/mozalloc_oom.h"
#include "nsRegion.h"
namespace mozilla {
......@@ -28,7 +29,12 @@ class LayerTimelineMarker : public TimelineMarker {
rect.mY = iterRect.Y();
rect.mWidth = iterRect.Width();
rect.mHeight = iterRect.Height();
aRectangles.AppendElement(rect, fallible);
if (!aRectangles.AppendElement(rect, fallible)) {
// XXX(Bug 1632090) Instead of extending the array 1-by-1 (which might
// involve multiple reallocations) and potentially crashing here,
// SetCapacity could be called outside the loop once.
mozalloc_handle_oom(0);
}
}
}
......
......@@ -1145,9 +1145,14 @@ void KeyframeEffect::GetProperties(
if (segment.mFromKey == segment.mToKey) {
fromValue.mEasing.Reset();
}
// The following won't fail since we have already allocated the capacity
// above.
propertyDetails.mValues.AppendElement(fromValue, mozilla::fallible);
// Even though we called SetCapacity before, this could fail, since we
// might add multiple elements to propertyDetails.mValues for an element
// of property.mSegments in the cases mentioned below.
if (!propertyDetails.mValues.AppendElement(fromValue,
mozilla::fallible)) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return;
}
// Normally we can ignore the to-value for this segment since it is
// identical to the from-value from the next segment. However, we need
......@@ -1164,7 +1169,11 @@ void KeyframeEffect::GetProperties(
// last property value or before a sudden jump so we just drop the
// easing property altogether.
toValue.mEasing.Reset();
propertyDetails.mValues.AppendElement(toValue, mozilla::fallible);
if (!propertyDetails.mValues.AppendElement(toValue,
mozilla::fallible)) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return;
}
}
}
......
......@@ -2626,7 +2626,8 @@ static nsresult GetPartialTextRect(nsLayoutUtils::RectCallback* aCallback,
nsIFrame::TextOffsetType::OffsetsInContentText,
nsIFrame::TrailingWhitespace::DontTrim);
aTextList->AppendElement(renderedText.mString, fallible);
NS_ENSURE_TRUE(aTextList->AppendElement(renderedText.mString, fallible),
NS_ERROR_OUT_OF_MEMORY);
}
}
}
......
......@@ -135,7 +135,15 @@ void DocumentL10n::TriggerInitialDocumentTranslation() {
Element* elem = elements.ElementAt(i - 1);
MOZ_RELEASE_ASSERT(elem->HasAttr(nsGkAtoms::datal10nid));
if (!elem->HasElementCreatedFromPrototypeAndHasUnmodifiedL10n()) {
nonProtoElements.AppendElement(*elem, fallible);
if (!nonProtoElements.AppendElement(*elem, fallible)) {
mozalloc_handle_oom(0);
}
// XXX(Bug 1631381) Consider making this fallible again like this:
// if (NS_WARN_IF(!nonProtoElements.AppendElement(*elem, fallible))) {
// InitialDocumentTranslationCompleted();
// mReady->MaybeRejectWithUndefined();
// return;
// }
elements.RemoveElement(elem);
}
i--;
......
......@@ -131,7 +131,9 @@ void L10nMutations::FlushPendingTranslations() {
continue;
}
elements.AppendElement(*elem, fallible);
if (!elements.AppendElement(*elem, fallible)) {
mozalloc_handle_oom(0);
}
}
mPendingElementsHash.Clear();
......
......@@ -876,8 +876,8 @@ static Sequence<nsString> UnboxSessionTypes(
sessionTypes = aSessionTypes.Value();
} else {
// Note: fallible. Results in an empty array.
sessionTypes.AppendElement(ToString(MediaKeySessionType::Temporary),
mozilla::fallible);
(void)sessionTypes.AppendElement(ToString(MediaKeySessionType::Temporary),
mozilla::fallible);
}
return sessionTypes;
}
......
......@@ -67,7 +67,10 @@ static nsresult GetAbsoluteURL(const nsAString& aUrl, nsIURI* aBaseUri,
already_AddRefed<PresentationRequest> PresentationRequest::Constructor(
const GlobalObject& aGlobal, const nsAString& aUrl, ErrorResult& aRv) {
Sequence<nsString> urls;
urls.AppendElement(aUrl, fallible);
if (!urls.AppendElement(aUrl, fallible)) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
}
return Constructor(aGlobal, urls, aRv);
}
......
......@@ -1648,7 +1648,9 @@ nsCSPContext::ToJSON(nsAString& outCSPinJSON) {
for (uint32_t p = 0; p < mPolicies.Length(); p++) {
dom::CSP jsonCSP;
mPolicies[p]->toDomCSPStruct(jsonCSP);
jsonPolicies.mCsp_policies.Value().AppendElement(jsonCSP, fallible);
if (!jsonPolicies.mCsp_policies.Value().AppendElement(jsonCSP, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
}
// convert the gathered information to JSON
......
......@@ -1092,7 +1092,12 @@ void nsCSPDirective::toDomCSPStruct(mozilla::dom::CSP& outCSP) const {
for (uint32_t i = 0; i < mSrcs.Length(); i++) {
src.Truncate();
mSrcs[i]->toString(src);
srcs.AppendElement(src, mozilla::fallible);
if (!srcs.AppendElement(src, mozilla::fallible)) {
// XXX(Bug 1632090) Instead of extending the array 1-by-1 (which might
// involve multiple reallocations) and potentially crashing here,
// SetCapacity could be called outside the loop once.
mozalloc_handle_oom(0);
}
}
switch (mDirective) {
......
......@@ -161,7 +161,11 @@ void SVGMotionSMILAnimationFunction::RebuildPathAndVerticesFromBasicAttrs(
if (HasAttr(nsGkAtoms::from)) {
const nsAString& fromStr = GetAttr(nsGkAtoms::from)->GetStringValue();
success = pathGenerator.MoveToAbsolute(fromStr);
mPathVertices.AppendElement(0.0, fallible);
// XXX(Bug 1631371) Check if this should use a fallible operation as it
// pretended earlier.
if (!mPathVertices.AppendElement(0.0, fallible)) {
mozalloc_handle_oom(0);
}
} else {
// Create dummy 'from' value at 0,0, if we're doing by-animation.
// (NOTE: We don't add the dummy 0-point to our list for *to-animation*,
......@@ -169,7 +173,11 @@ void SVGMotionSMILAnimationFunction::RebuildPathAndVerticesFromBasicAttrs(
// expect a dummy value. It only expects one value: the final 'to' value.)
pathGenerator.MoveToOrigin();
if (!HasAttr(nsGkAtoms::to)) {
mPathVertices.AppendElement(0.0, fallible);
// XXX(Bug 1631371) Check if this should use a fallible operation as it
// pretended earlier.
if (!mPathVertices.AppendElement(0.0, fallible)) {
mozalloc_handle_oom(0);
}
}
success = true;
}
......@@ -187,7 +195,11 @@ void SVGMotionSMILAnimationFunction::RebuildPathAndVerticesFromBasicAttrs(
success = pathGenerator.LineToRelative(byStr, dist);
}
if (success) {
mPathVertices.AppendElement(dist, fallible);
// XXX(Bug 1631371) Check if this should use a fallible operation as it
// pretended earlier.
if (!mPathVertices.AppendElement(dist, fallible)) {
mozalloc_handle_oom(0);
}
}
}
}
......
......@@ -334,7 +334,8 @@ bool SVGTransformListSMILType::GetTransforms(
for (uint32_t i = 0; i < smilTransforms.Length(); ++i) {
// No need to check the return value below since we have already allocated
// the necessary space
aTransforms.AppendElement(smilTransforms[i].ToSVGTransform(), fallible);
(void)aTransforms.AppendElement(smilTransforms[i].ToSVGTransform(),
fallible);
}
return true;
}
......
......@@ -71,7 +71,9 @@ void XRInputSourceArray::Update(XRSession* aSession) {
addInit.mBubbles = false;
addInit.mCancelable = false;
addInit.mSession = aSession;
addInit.mAdded.AppendElement(*inputSource, mozilla::fallible);
if (!addInit.mAdded.AppendElement(*inputSource, mozilla::fallible)) {
mozalloc_handle_oom(0);
}
}
// If added, updating the current controller states.
if (inputSource) {
......@@ -110,7 +112,12 @@ void XRInputSourceArray::DispatchInputSourceRemovedEvent(
init.mBubbles = false;
init.mCancelable = false;
init.mSession = aSession;
init.mRemoved.AppendElement(*input, mozilla::fallible);
if (!init.mRemoved.AppendElement(*input, mozilla::fallible)) {
// XXX(Bug 1632090) Instead of extending the array 1-by-1 (which might
// involve multiple reallocations) and potentially crashing here,
// SetCapacity could be called outside the loop once.
mozalloc_handle_oom(0);
}
}
if (init.mRemoved.Length()) {
......
......@@ -419,9 +419,11 @@ static UniqueSECItem KeyHandleFromPrivateKey(
// It's OK to ignore the return values here because we're writing into
// pre-allocated space
keyHandleBuf.AppendElement(SoftTokenHandle::Version1, mozilla::fallible);
keyHandleBuf.AppendElement(sizeof(saltParam), mozilla::fallible);
keyHandleBuf.AppendElements(saltParam, sizeof(saltParam), mozilla::fallible);
(void)keyHandleBuf.AppendElement(SoftTokenHandle::Version1,
mozilla::fallible);
(void)keyHandleBuf.AppendElement(sizeof(saltParam), mozilla::fallible);
(void)keyHandleBuf.AppendElements(saltParam, sizeof(saltParam),
mozilla::fallible);
keyHandleBuf.AppendSECItem(wrappedKey.get());
UniqueSECItem keyHandle(::SECITEM_AllocItem(nullptr, nullptr, 0));
......@@ -692,9 +694,9 @@ RefPtr<U2FRegisterPromise> U2FSoftTokenManager::Register(
// // It's OK to ignore the return values here because we're writing into
// // pre-allocated space
signedDataBuf.AppendElement(0x00, mozilla::fallible);
signedDataBuf.AppendElements(rpIdHash, mozilla::fallible);
signedDataBuf.AppendElements(clientDataHash, mozilla::fallible);
(void)signedDataBuf.AppendElement(0x00, mozilla::fallible);
(void)signedDataBuf.AppendElements(rpIdHash, mozilla::fallible);
(void)signedDataBuf.AppendElements(clientDataHash, mozilla::fallible);
signedDataBuf.AppendSECItem(keyHandleItem.get());
signedDataBuf.AppendSECItem(pubKey->u.ec.publicValue);
......@@ -717,9 +719,9 @@ RefPtr<U2FRegisterPromise> U2FSoftTokenManager::Register(
return U2FRegisterPromise::CreateAndReject(NS_ERROR_OUT_OF_MEMORY,
__func__);
}
registrationBuf.AppendElement(0x05, mozilla::fallible);
(void)registrationBuf.AppendElement(0x05, mozilla::fallible);
registrationBuf.AppendSECItem(pubKey->u.ec.publicValue);
registrationBuf.AppendElement(keyHandleItem->len, mozilla::fallible);
(void)registrationBuf.AppendElement(keyHandleItem->len, mozilla::fallible);
registrationBuf.AppendSECItem(keyHandleItem.get());
registrationBuf.AppendSECItem(attestCert.get()->derCert);
registrationBuf.AppendSECItem(signatureItem);
......@@ -893,12 +895,12 @@ RefPtr<U2FSignPromise> U2FSoftTokenManager::Sign(
// It's OK to ignore the return values here because we're writing into
// pre-allocated space
signedDataBuf.AppendElements(chosenAppId.Elements(), chosenAppId.Length(),
mozilla::fallible);
signedDataBuf.AppendElement(0x01, mozilla::fallible);
(void)signedDataBuf.AppendElements(chosenAppId.Elements(),
chosenAppId.Length(), mozilla::fallible);
(void)signedDataBuf.AppendElement(0x01, mozilla::fallible);
signedDataBuf.AppendSECItem(counterItem);
signedDataBuf.AppendElements(clientDataHash.Elements(),
clientDataHash.Length(), mozilla::fallible);
(void)signedDataBuf.AppendElements(
clientDataHash.Elements(), clientDataHash.Length(), mozilla::fallible);
if (MOZ_LOG_TEST(gNSSTokenLog, LogLevel::Debug)) {
nsAutoCString base64;
......@@ -932,7 +934,7 @@ RefPtr<U2FSignPromise> U2FSoftTokenManager::Sign(
// It's OK to ignore the return values here because we're writing into
// pre-allocated space
signatureDataBuf.AppendElement(0x01, mozilla::fallible);
(void)signatureDataBuf.AppendElement(0x01, mozilla::fallible);
signatureDataBuf.AppendSECItem(counterItem);
signatureDataBuf.AppendSECItem(signatureItem);
......
......@@ -150,10 +150,10 @@ nsresult AssembleAuthenticatorData(const CryptoBuffer& rpIdHashBuf,
return NS_ERROR_INVALID_ARG;
}
authDataBuf.AppendElements(rpIdHashBuf, mozilla::fallible);
authDataBuf.AppendElement(flags, mozilla::fallible);
authDataBuf.AppendElements(counterBuf, mozilla::fallible);
authDataBuf.AppendElements(attestationDataBuf, mozilla::fallible);
(void)authDataBuf.AppendElements(rpIdHashBuf, mozilla::fallible);
(void)authDataBuf.AppendElement(flags, mozilla::fallible);
(void)authDataBuf.AppendElements(counterBuf, mozilla::fallible);
(void)authDataBuf.AppendElements(attestationDataBuf, mozilla::fallible);
return NS_OK;
}
......@@ -175,13 +175,13 @@ nsresult AssembleAttestationData(const CryptoBuffer& aaguidBuf,
return NS_ERROR_INVALID_ARG;
}
attestationDataBuf.AppendElements(aaguidBuf, mozilla::fallible);
attestationDataBuf.AppendElement((keyHandleBuf.Length() >> 8) & 0xFF,
mozilla::fallible);
attestationDataBuf.AppendElement((keyHandleBuf.Length() >> 0) & 0xFF,
mozilla::fallible);
attestationDataBuf.AppendElements(keyHandleBuf, mozilla::fallible);
attestationDataBuf.AppendElements(pubKeyObj, mozilla::fallible);
(void)attestationDataBuf.AppendElements(aaguidBuf, mozilla::fallible);
(void)attestationDataBuf.AppendElement((keyHandleBuf.Length() >> 8) & 0xFF,
mozilla::fallible);
(void)attestationDataBuf.AppendElement((keyHandleBuf.Length() >> 0) & 0xFF,
mozilla::fallible);
(void)attestationDataBuf.AppendElements(keyHandleBuf, mozilla::fallible);
(void)attestationDataBuf.AppendElements(pubKeyObj, mozilla::fallible);
return NS_OK;
}
......@@ -207,7 +207,8 @@ nsresult AssembleAttestationObject(const CryptoBuffer& aRpIdHash,
// FIDO U2F devices have no AAGUIDs, so they'll be all zeros until we add
// support for CTAP2 devices.
for (int i = 0; i < 16; i++) {
aaguidBuf.AppendElement(0x00, mozilla::fallible);
// SetCapacity was just called, these cannot fail.
(void)aaguidBuf.AppendElement(0x00, mozilla::fallible);
}
// During create credential, counter is always 0 for U2F
......@@ -216,10 +217,11 @@ nsresult AssembleAttestationObject(const CryptoBuffer& aRpIdHash,
if (NS_WARN_IF(!counterBuf.SetCapacity(4, mozilla::fallible))) {
return NS_ERROR_OUT_OF_MEMORY;
}
counterBuf.AppendElement(0x00, mozilla::fallible);
counterBuf.AppendElement(0x00, mozilla::fallible);
counterBuf.AppendElement(0x00, mozilla::fallible);
counterBuf.AppendElement(0x00, mozilla::fallible);
// SetCapacity was just called, these cannot fail.
(void)counterBuf.AppendElement(0x00, mozilla::fallible);
(void)counterBuf.AppendElement(0x00, mozilla::fallible);
(void)counterBuf.AppendElement(0x00, mozilla::fallible);
(void)counterBuf.AppendElement(0x00, mozilla::fallible);
// Construct the Attestation Data, which slots into the end of the
// Authentication Data buffer.
......
......@@ -19,7 +19,12 @@ struct APZTestDataToJSConverter {
void (*aElementConverter)(const Key&, const Value&,
KeyValuePair&)) {
for (auto it = aFrom.begin(); it != aFrom.end(); ++it) {
aOutTo.AppendElement(fallible);
if (!aOutTo.AppendElement(fallible)) {
// XXX(Bug 1632090) Instead of extending the array 1-by-1 (which might
// involve multiple reallocations) and potentially crashing here,
// SetCapacity could be called outside the loop once.
mozalloc_handle_oom(0);
}
aElementConverter(it->first, it->second, aOutTo.LastElement());
}
}
......@@ -29,7 +34,12 @@ struct APZTestDataToJSConverter {
dom::Sequence<Target>& aOutTo,
void (*aElementConverter)(const Src&, Target&)) {
for (auto it = aFrom.begin(); it != aFrom.end(); ++it) {
aOutTo.AppendElement(fallible);
if (!aOutTo.AppendElement(fallible)) {
// XXX(Bug 1632090) Instead of extending the array 1-by-1 (which might
// involve multiple reallocations) and potentially crashing here,
// SetCapacity could be called outside the loop once.
mozalloc_handle_oom(0);
}
aElementConverter(*it, aOutTo.LastElement());
}
}
......
......@@ -374,7 +374,9 @@ void MediaPipeline::GetContributingSourceStats(
if (!info.second.Expired(expiry)) {
RTCRTPContributingSourceStats stats;
info.second.GetWebidlInstance(stats, aInboundRtpStreamId);
aArr.AppendElement(stats, fallible);
if (!aArr.AppendElement(stats, fallible)) {
mozalloc_handle_oom(0);
}
}
}
}
......
......@@ -31,6 +31,7 @@
#include "runnable_utils.h"
#include "mozilla/Algorithm.h"
#include "mozilla/Telemetry.h"
#include "mozilla/dom/RTCStatsReportBinding.h"
......@@ -963,9 +964,15 @@ MediaTransportHandlerSTS::GetIceLog(const nsCString& aPattern) {
if (logs) {
logs->Filter(aPattern.get(), 0, &result);
}
/// XXX(Bug 1631386) Check if we should reject the promise instead of
/// crashing in an OOM situation.
if (!converted.SetCapacity(result.size(), fallible)) {
mozalloc_handle_oom(sizeof(nsString) * result.size());
}
for (auto& line : result) {
converted.AppendElement(NS_ConvertUTF8toUTF16(line.c_str()),
fallible);
// Cannot fail, SetCapacity was called before.
(void)converted.AppendElement(NS_ConvertUTF8toUTF16(line.c_str()),
fallible);
}
return IceLogPromise::CreateAndResolve(std::move(converted), __func__);
});
......@@ -1054,9 +1061,16 @@ static void ToRTCIceCandidateStats(
}
cand.mProxied.Construct(NS_ConvertASCIItoUTF16(
candidate.is_proxied ? "proxied" : "non-proxied"));
stats->mIceCandidateStats.AppendElement(cand, fallible);
if (!stats->mIceCandidateStats.AppendElement(cand, fallible)) {
// XXX(Bug 1632090) Instead of extending the array 1-by-1 (which might
// involve multiple reallocations) and potentially crashing here,
// SetCapacity could be called outside the loop once.
mozalloc_handle_oom(0);
}
if (candidate.trickled) {
stats->mTrickledIceCandidateStats.AppendElement(cand, fallible);
if (!stats->mTrickledIceCandidateStats.AppendElement(cand, fallible)) {
mozalloc_handle_oom(0);
}
}
}
}
......@@ -1102,7 +1116,12 @@ void MediaTransportHandlerSTS::GetIceStats(
s.mLastPacketReceivedTimestamp.Construct(candPair.ms_since_last_recv);
s.mState.Construct(dom::RTCStatsIceCandidatePairState(candPair.state));
s.mComponentId.Construct(candPair.component_id);
aStats->mIceCandidatePairStats.AppendElement(s, fallible);
if (!aStats->mIceCandidatePairStats.AppendElement(s, fallible)) {
// XXX(Bug 1632090) Instead of extending the array 1-by-1 (which might
// involve multiple reallocations) and potentially crashing here,
// SetCapacity could be called outside the loop once.
mozalloc_handle_oom(0);
}
}
std::vector<NrIceCandidate> candidates;
......@@ -1112,8 +1131,13 @@ void MediaTransportHandlerSTS::GetIceStats(
mSignaledAddresses);
// add the local candidates unparsed string to a sequence
for (const auto& candidate : candidates) {
aStats->mRawLocalCandidates.AppendElement(
NS_ConvertASCIItoUTF16(candidate.label.c_str()), fallible);
if (!aStats->mRawLocalCandidates.AppendElement(
NS_ConvertASCIItoUTF16(candidate.label.c_str()), fallible)) {
// XXX(Bug 1632090) Instead of extending the array 1-by-1 (which might
// involve multiple reallocations) and potentially crashing here,
// SetCapacity could be called outside the loop once.
mozalloc_handle_oom(0);
}
}
}
candidates.clear();
......@@ -1124,8 +1148,13 @@ void MediaTransportHandlerSTS::GetIceStats(
mSignaledAddresses);
// add the remote candidates unparsed string to a sequence
for (const auto& candidate : candidates) {
aStats->mRawRemoteCandidates.AppendElement(
NS_ConvertASCIItoUTF16(candidate.label.c_str()), fallible);
if (!aStats->mRawRemoteCandidates.AppendElement(
NS_ConvertASCIItoUTF16(candidate.label.c_str()), fallible)) {
// XXX(Bug 1632090) Instead of extending the array 1-by-1 (which might
// involve multiple reallocations) and potentially crashing here,
// SetCapacity could be called outside the loop once.
mozalloc_handle_oom(0);
}
}
}
}
......
......@@ -2151,7 +2151,13 @@ void PeerConnectionImpl::OnSetDescriptionSuccess(bool rollback, bool remote) {
MOZ_ASSERT(false);
continue;
}
streams.AppendElement(*stream, fallible);
if (!streams.AppendElement(*stream, fallible)) {
// XXX(Bug 1632090) Instead of extending the array 1-by-1 (which
// might involve multiple reallocations) and potentially
// crashing here, SetCapacity could be called outside the loop
// once.
mozalloc_handle_oom(0);
}
}
mPCObserver->FireTrackEvent(*trackEvent.mReceiver, streams, jrv);
}
......@@ -2492,7 +2498,9 @@ static UniquePtr<dom::RTCStatsCollection> GetSenderStats_s(
s.mBytesReceived.Construct(bytesReceived);
s.mPacketsLost.Construct(packetsLost);
rtt.apply([&s](auto r) { s.mRoundTripTime.Construct(r); });
report->mRemoteInboundRtpStreamStats.AppendElement(s, fallible);
if (!report->mRemoteInboundRtpStreamStats.AppendElement(s, fallible)) {
mozalloc_handle_oom(0);
}
}
}
// Then, fill in local side (with cross-link to remote only if present)
......@@ -2541,7 +2549,9 @@ static UniquePtr<dom::RTCStatsCollection> GetSenderStats_s(
qpSum.apply([&s](uint64_t aQp) { s.mQpSum.Construct(aQp); });
}
});
report->mOutboundRtpStreamStats.AppendElement(s, fallible);
if (!report->mOutboundRtpStreamStats.AppendElement(s, fallible)) {
mozalloc_handle_oom(0);
}
return report;
}
......@@ -2582,7 +2592,9 @@ void AssignWithOpaqueIds(dom::Sequence<T>& aSource, dom::Sequence<T>& aDest,
for (auto& stat : aSource) {
stat.mId.Value() = aGenerator->Id(stat.mId.Value());
}
aDest.AppendElements(aSource, fallible);
if (!aDest.AppendElements(aSource, fallible)) {
mozalloc_handle_oom(0);
}
}
template <class T>
......@@ -2665,8 +2677,13 @@ RefPtr<dom::RTCStatsReportPromise> PeerConnectionImpl::GetStats(
if (aInternalStats && mJsepSession) {
for (const auto& candidate : mRawTrickledCandidates) {
report->mRawRemoteCandidates.AppendElement(
NS_ConvertASCIItoUTF16(candidate.c_str()), fallible);
if (!report->mRawRemoteCandidates.AppendElement(
NS_ConvertASCIItoUTF16(candidate.c_str()), fallible)) {
// XXX(Bug 1632090) Instead of extending the array 1-by-1 (which might
// involve multiple reallocations) and potentially crashing here,
// SetCapacity could be called outside the loop once.
mozalloc_handle_oom(0);
}
}
if (mJsepSession) {
......@@ -2738,10 +2755,16 @@ RefPtr<dom::RTCStatsReportPromise> PeerConnectionImpl::GetStats(
report->mRtpContributingSourceStats, idGen);
AssignWithOpaqueIds(stats->mTrickledIceCandidateStats,
report->mTrickledIceCandidateStats, idGen);
report->mRawLocalCandidates.AppendElements(
stats->mRawLocalCandidates, fallible);
report->mRawRemoteCandidates.AppendElements(
stats->mRawRemoteCandidates, fallible);
if (!report->mRawLocalCandidates.AppendElements(
stats->mRawLocalCandidates, fallible) ||
!report->mRawRemoteCandidates.AppendElements(
stats->mRawRemoteCandidates, fallible)) {
// XXX(Bug 1632090) Instead of extending the array 1-by-1 (which
// might involve multiple reallocations) and potentially
// crashing here, SetCapacity could be called outside the loop
// once.
mozalloc_handle_oom(0);
}
}
return dom::RTCStatsReportPromise::CreateAndResolve(
std::move(report), __func__);
......
......@@ -191,7 +191,9 @@ static UniquePtr<dom::RTCStatsCollection> GetReceiverStats_s(
s.mLocalId.Construct(localId);
s.mPacketsSent.Construct(packetsSent);
s.mBytesSent.Construct(bytesSent);
report->mRemoteOutboundRtpStreamStats.AppendElement(s, fallible);
if (!report->mRemoteOutboundRtpStreamStats.AppendElement(s, fallible)) {
mozalloc_handle_oom(0);
}
}
// Then, fill in local side (with cross-link to remote only if present)
......@@ -244,7 +246,9 @@ static UniquePtr<dom::RTCStatsCollection> GetReceiverStats_s(
s.mFramesDecoded.Construct(framesDecoded);
}
});
report->mInboundRtpStreamStats.AppendElement(s, fallible);
if (!report->mInboundRtpStreamStats.AppendElement(s, fallible)) {
mozalloc_handle_oom(0);
}
// Fill in Contributing Source statistics
aPipeline->GetContributingSourceStats(localId,
......
......@@ -254,7 +254,9 @@ static void OnStatsReport_m(
for (auto& report : aReports) {