| File: | var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp |
| Warning: | line 139, column 12 Value stored to 'rv' during its initialization is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
| 2 | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
| 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
| 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 6 | |
| 7 | #include "mozilla/css/StreamLoader.h" |
| 8 | #include "mozilla/StaticPrefs_network.h" |
| 9 | #include "mozilla/Encoding.h" |
| 10 | #include "mozilla/glean/GleanMetrics.h" |
| 11 | #include "mozilla/TaskQueue.h" |
| 12 | #include "mozilla/dom/CacheExpirationTime.h" |
| 13 | #include "nsContentUtils.h" |
| 14 | #include "nsIAsyncVerifyRedirectCallback.h" |
| 15 | #include "nsIChannel.h" |
| 16 | #include "nsIInputStream.h" |
| 17 | #include "nsIThreadRetargetableRequest.h" |
| 18 | #include "nsIStreamTransportService.h" |
| 19 | #include "nsNetCID.h" |
| 20 | #include "nsNetUtil.h" |
| 21 | #include "nsProxyRelease.h" |
| 22 | #include "nsServiceManagerUtils.h" |
| 23 | |
| 24 | namespace mozilla::css { |
| 25 | |
| 26 | StreamLoader::StreamLoader(SheetLoadData& aSheetLoadData) |
| 27 | : mSheetLoadData(&aSheetLoadData), |
| 28 | mStatus(NS_OK), |
| 29 | mMainThreadSheetLoadData(new nsMainThreadPtrHolder<SheetLoadData>( |
| 30 | "StreamLoader::SheetLoadData", mSheetLoadData, false)) {} |
| 31 | |
| 32 | StreamLoader::~StreamLoader() { |
| 33 | #ifdef NIGHTLY_BUILD1 |
| 34 | MOZ_RELEASE_ASSERT(mOnStopProcessingDone || mChannelOpenFailed)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mOnStopProcessingDone || mChannelOpenFailed)>::isValid , "invalid assertion condition"); if ((__builtin_expect(!!(!( !!(mOnStopProcessingDone || mChannelOpenFailed))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mOnStopProcessingDone || mChannelOpenFailed" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp" , 34); AnnotateMozCrashReason("MOZ_RELEASE_ASSERT" "(" "mOnStopProcessingDone || mChannelOpenFailed" ")"); do { *((volatile int*)__null) = 34; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 35 | #endif |
| 36 | } |
| 37 | |
| 38 | NS_IMPL_ISUPPORTS(StreamLoader, nsIStreamListener,MozExternalRefCountType StreamLoader::AddRef(void) { static_assert (!std::is_destructible_v<StreamLoader>, "Reference-counted class " "StreamLoader" " should not have a public destructor. " "Make this class's destructor non-public" ); do { static_assert( mozilla::detail::AssertionConditionType <decltype(int32_t(mRefCnt) >= 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) >= 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) >= 0" " (" "illegal refcnt" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp" , 40); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0" ") (" "illegal refcnt" ")"); do { *((volatile int*)__null) = 40; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); do { static_assert( mozilla::detail::AssertionConditionType <decltype("StreamLoader" != nullptr)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!("StreamLoader" != nullptr))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"StreamLoader\" != nullptr" " (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp" , 40); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"StreamLoader\" != nullptr" ") (" "Must specify a name" ")"); do { *((volatile int*)__null ) = 40; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership ("StreamLoader" " not thread-safe"); nsrefcnt count = ++mRefCnt ; NS_LogAddRef((this), (count), ("StreamLoader"), (uint32_t)( sizeof(*this))); return count; } MozExternalRefCountType StreamLoader ::Release(void) { do { static_assert( mozilla::detail::AssertionConditionType <decltype(int32_t(mRefCnt) > 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) > 0))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) > 0" " (" "dup release" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp" , 40); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0" ") (" "dup release" ")"); do { *((volatile int*)__null) = 40 ; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); do { static_assert( mozilla::detail::AssertionConditionType <decltype("StreamLoader" != nullptr)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!("StreamLoader" != nullptr))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"StreamLoader\" != nullptr" " (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp" , 40); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"StreamLoader\" != nullptr" ") (" "Must specify a name" ")"); do { *((volatile int*)__null ) = 40; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership ("StreamLoader" " not thread-safe"); const char* const nametmp = "StreamLoader"; nsrefcnt count = --mRefCnt; NS_LogRelease( (this), (count), (nametmp)); if (count == 0) { mRefCnt = 1; delete (this); return 0; } return count; } nsresult StreamLoader::QueryInterface (const nsIID& aIID, void** aInstancePtr) { do { if (!(aInstancePtr )) { NS_DebugBreak(NS_DEBUG_ASSERTION, "QueryInterface requires a non-NULL destination!" , "aInstancePtr", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp" , 40); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE ; static_assert(4 > 0, "Need more arguments to NS_INTERFACE_TABLE" ); static const QITableEntry table[] = { {&mozilla::detail ::kImplementedIID<StreamLoader, nsIStreamListener>, int32_t ( reinterpret_cast<char*>(static_cast<nsIStreamListener *>((StreamLoader*)0x1000)) - reinterpret_cast<char*> ((StreamLoader*)0x1000))}, {&mozilla::detail::kImplementedIID <StreamLoader, nsIThreadRetargetableStreamListener>, int32_t ( reinterpret_cast<char*>(static_cast<nsIThreadRetargetableStreamListener *>((StreamLoader*)0x1000)) - reinterpret_cast<char*> ((StreamLoader*)0x1000))}, {&mozilla::detail::kImplementedIID <StreamLoader, nsIChannelEventSink>, int32_t( reinterpret_cast <char*>(static_cast<nsIChannelEventSink*>((StreamLoader *)0x1000)) - reinterpret_cast<char*>((StreamLoader*)0x1000 ))}, {&mozilla::detail::kImplementedIID<StreamLoader, nsIInterfaceRequestor >, int32_t( reinterpret_cast<char*>(static_cast<nsIInterfaceRequestor *>((StreamLoader*)0x1000)) - reinterpret_cast<char*> ((StreamLoader*)0x1000))}, {&mozilla::detail::kImplementedIID <StreamLoader, nsISupports>, int32_t(reinterpret_cast< char*>(static_cast<nsISupports*>( static_cast<nsIStreamListener *>((StreamLoader*)0x1000))) - reinterpret_cast<char*> ((StreamLoader*)0x1000))}, { nullptr, 0 } } ; static_assert(std ::size(table) > 1, "need at least 1 interface"); rv = NS_TableDrivenQI (static_cast<void*>(this), aIID, aInstancePtr, table); return rv; } |
| 39 | nsIThreadRetargetableStreamListener, nsIChannelEventSink,MozExternalRefCountType StreamLoader::AddRef(void) { static_assert (!std::is_destructible_v<StreamLoader>, "Reference-counted class " "StreamLoader" " should not have a public destructor. " "Make this class's destructor non-public" ); do { static_assert( mozilla::detail::AssertionConditionType <decltype(int32_t(mRefCnt) >= 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) >= 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) >= 0" " (" "illegal refcnt" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp" , 40); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0" ") (" "illegal refcnt" ")"); do { *((volatile int*)__null) = 40; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); do { static_assert( mozilla::detail::AssertionConditionType <decltype("StreamLoader" != nullptr)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!("StreamLoader" != nullptr))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"StreamLoader\" != nullptr" " (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp" , 40); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"StreamLoader\" != nullptr" ") (" "Must specify a name" ")"); do { *((volatile int*)__null ) = 40; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership ("StreamLoader" " not thread-safe"); nsrefcnt count = ++mRefCnt ; NS_LogAddRef((this), (count), ("StreamLoader"), (uint32_t)( sizeof(*this))); return count; } MozExternalRefCountType StreamLoader ::Release(void) { do { static_assert( mozilla::detail::AssertionConditionType <decltype(int32_t(mRefCnt) > 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) > 0))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) > 0" " (" "dup release" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp" , 40); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0" ") (" "dup release" ")"); do { *((volatile int*)__null) = 40 ; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); do { static_assert( mozilla::detail::AssertionConditionType <decltype("StreamLoader" != nullptr)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!("StreamLoader" != nullptr))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"StreamLoader\" != nullptr" " (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp" , 40); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"StreamLoader\" != nullptr" ") (" "Must specify a name" ")"); do { *((volatile int*)__null ) = 40; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership ("StreamLoader" " not thread-safe"); const char* const nametmp = "StreamLoader"; nsrefcnt count = --mRefCnt; NS_LogRelease( (this), (count), (nametmp)); if (count == 0) { mRefCnt = 1; delete (this); return 0; } return count; } nsresult StreamLoader::QueryInterface (const nsIID& aIID, void** aInstancePtr) { do { if (!(aInstancePtr )) { NS_DebugBreak(NS_DEBUG_ASSERTION, "QueryInterface requires a non-NULL destination!" , "aInstancePtr", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp" , 40); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE ; static_assert(4 > 0, "Need more arguments to NS_INTERFACE_TABLE" ); static const QITableEntry table[] = { {&mozilla::detail ::kImplementedIID<StreamLoader, nsIStreamListener>, int32_t ( reinterpret_cast<char*>(static_cast<nsIStreamListener *>((StreamLoader*)0x1000)) - reinterpret_cast<char*> ((StreamLoader*)0x1000))}, {&mozilla::detail::kImplementedIID <StreamLoader, nsIThreadRetargetableStreamListener>, int32_t ( reinterpret_cast<char*>(static_cast<nsIThreadRetargetableStreamListener *>((StreamLoader*)0x1000)) - reinterpret_cast<char*> ((StreamLoader*)0x1000))}, {&mozilla::detail::kImplementedIID <StreamLoader, nsIChannelEventSink>, int32_t( reinterpret_cast <char*>(static_cast<nsIChannelEventSink*>((StreamLoader *)0x1000)) - reinterpret_cast<char*>((StreamLoader*)0x1000 ))}, {&mozilla::detail::kImplementedIID<StreamLoader, nsIInterfaceRequestor >, int32_t( reinterpret_cast<char*>(static_cast<nsIInterfaceRequestor *>((StreamLoader*)0x1000)) - reinterpret_cast<char*> ((StreamLoader*)0x1000))}, {&mozilla::detail::kImplementedIID <StreamLoader, nsISupports>, int32_t(reinterpret_cast< char*>(static_cast<nsISupports*>( static_cast<nsIStreamListener *>((StreamLoader*)0x1000))) - reinterpret_cast<char*> ((StreamLoader*)0x1000))}, { nullptr, 0 } } ; static_assert(std ::size(table) > 1, "need at least 1 interface"); rv = NS_TableDrivenQI (static_cast<void*>(this), aIID, aInstancePtr, table); return rv; } |
| 40 | nsIInterfaceRequestor)MozExternalRefCountType StreamLoader::AddRef(void) { static_assert (!std::is_destructible_v<StreamLoader>, "Reference-counted class " "StreamLoader" " should not have a public destructor. " "Make this class's destructor non-public" ); do { static_assert( mozilla::detail::AssertionConditionType <decltype(int32_t(mRefCnt) >= 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) >= 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) >= 0" " (" "illegal refcnt" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp" , 40); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0" ") (" "illegal refcnt" ")"); do { *((volatile int*)__null) = 40; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); do { static_assert( mozilla::detail::AssertionConditionType <decltype("StreamLoader" != nullptr)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!("StreamLoader" != nullptr))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"StreamLoader\" != nullptr" " (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp" , 40); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"StreamLoader\" != nullptr" ") (" "Must specify a name" ")"); do { *((volatile int*)__null ) = 40; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership ("StreamLoader" " not thread-safe"); nsrefcnt count = ++mRefCnt ; NS_LogAddRef((this), (count), ("StreamLoader"), (uint32_t)( sizeof(*this))); return count; } MozExternalRefCountType StreamLoader ::Release(void) { do { static_assert( mozilla::detail::AssertionConditionType <decltype(int32_t(mRefCnt) > 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) > 0))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) > 0" " (" "dup release" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp" , 40); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0" ") (" "dup release" ")"); do { *((volatile int*)__null) = 40 ; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); do { static_assert( mozilla::detail::AssertionConditionType <decltype("StreamLoader" != nullptr)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!("StreamLoader" != nullptr))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"StreamLoader\" != nullptr" " (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp" , 40); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"StreamLoader\" != nullptr" ") (" "Must specify a name" ")"); do { *((volatile int*)__null ) = 40; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership ("StreamLoader" " not thread-safe"); const char* const nametmp = "StreamLoader"; nsrefcnt count = --mRefCnt; NS_LogRelease( (this), (count), (nametmp)); if (count == 0) { mRefCnt = 1; delete (this); return 0; } return count; } nsresult StreamLoader::QueryInterface (const nsIID& aIID, void** aInstancePtr) { do { if (!(aInstancePtr )) { NS_DebugBreak(NS_DEBUG_ASSERTION, "QueryInterface requires a non-NULL destination!" , "aInstancePtr", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp" , 40); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE ; static_assert(4 > 0, "Need more arguments to NS_INTERFACE_TABLE" ); static const QITableEntry table[] = { {&mozilla::detail ::kImplementedIID<StreamLoader, nsIStreamListener>, int32_t ( reinterpret_cast<char*>(static_cast<nsIStreamListener *>((StreamLoader*)0x1000)) - reinterpret_cast<char*> ((StreamLoader*)0x1000))}, {&mozilla::detail::kImplementedIID <StreamLoader, nsIThreadRetargetableStreamListener>, int32_t ( reinterpret_cast<char*>(static_cast<nsIThreadRetargetableStreamListener *>((StreamLoader*)0x1000)) - reinterpret_cast<char*> ((StreamLoader*)0x1000))}, {&mozilla::detail::kImplementedIID <StreamLoader, nsIChannelEventSink>, int32_t( reinterpret_cast <char*>(static_cast<nsIChannelEventSink*>((StreamLoader *)0x1000)) - reinterpret_cast<char*>((StreamLoader*)0x1000 ))}, {&mozilla::detail::kImplementedIID<StreamLoader, nsIInterfaceRequestor >, int32_t( reinterpret_cast<char*>(static_cast<nsIInterfaceRequestor *>((StreamLoader*)0x1000)) - reinterpret_cast<char*> ((StreamLoader*)0x1000))}, {&mozilla::detail::kImplementedIID <StreamLoader, nsISupports>, int32_t(reinterpret_cast< char*>(static_cast<nsISupports*>( static_cast<nsIStreamListener *>((StreamLoader*)0x1000))) - reinterpret_cast<char*> ((StreamLoader*)0x1000))}, { nullptr, 0 } } ; static_assert(std ::size(table) > 1, "need at least 1 interface"); rv = NS_TableDrivenQI (static_cast<void*>(this), aIID, aInstancePtr, table); return rv; } |
| 41 | |
| 42 | /* nsIRequestObserver implementation */ |
| 43 | NS_IMETHODIMPnsresult |
| 44 | StreamLoader::OnStartRequest(nsIRequest* aRequest) { |
| 45 | MOZ_ASSERT(aRequest)do { static_assert( mozilla::detail::AssertionConditionType< decltype(aRequest)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(aRequest))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("aRequest", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp" , 45); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aRequest" ")" ); do { *((volatile int*)__null) = 45; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 46 | mRequest = aRequest; |
| 47 | mSheetLoadData->NotifyStart(aRequest); |
| 48 | |
| 49 | // It's kinda bad to let Web content send a number that results |
| 50 | // in a potentially large allocation directly, but efficiency of |
| 51 | // compression bombs is so great that it doesn't make much sense |
| 52 | // to require a site to send one before going ahead and allocating. |
| 53 | if (nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest)) { |
| 54 | int64_t length; |
| 55 | nsresult rv = channel->GetContentLength(&length); |
| 56 | if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && length > 0) { |
| 57 | CheckedInt<nsACString::size_type> checkedLength(length); |
| 58 | if (!checkedLength.isValid()) { |
| 59 | return (mStatus = NS_ERROR_OUT_OF_MEMORY); |
| 60 | } |
| 61 | if (!mBytes.SetCapacity(checkedLength.value(), fallible)) { |
| 62 | return (mStatus = NS_ERROR_OUT_OF_MEMORY); |
| 63 | } |
| 64 | } |
| 65 | NS_GetFinalChannelURI(channel, getter_AddRefs(mFinalChannelURI)); |
| 66 | nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager(); |
| 67 | // we dont return on error here as the error is handled in |
| 68 | // SheetLoadData::VerifySheetReadyToParse |
| 69 | Unused << secMan->GetChannelResultPrincipal( |
| 70 | channel, getter_AddRefs(mChannelResultPrincipal)); |
| 71 | } |
| 72 | if (nsCOMPtr<nsIThreadRetargetableRequest> rr = do_QueryInterface(aRequest)) { |
| 73 | nsCOMPtr<nsIEventTarget> sts = |
| 74 | do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID"@mozilla.org/network/stream-transport-service;1"); |
| 75 | RefPtr queue = |
| 76 | TaskQueue::Create(sts.forget(), "css::StreamLoader Delivery Queue"); |
| 77 | rr->RetargetDeliveryTo(queue); |
| 78 | } |
| 79 | |
| 80 | mSheetLoadData->SetMinimumExpirationTime( |
| 81 | nsContentUtils::GetSubresourceCacheExpirationTime(aRequest, |
| 82 | mSheetLoadData->mURI)); |
| 83 | |
| 84 | // We need to block block resolution of parse promise until we receive |
| 85 | // OnStopRequest on Main thread. This is necessary because parse promise |
| 86 | // resolution fires OnLoad event OnLoad event must not be dispatched until |
| 87 | // OnStopRequest in main thread is processed, for stuff like performance |
| 88 | // resource entries. |
| 89 | mSheetLoadData->mSheet->BlockParsePromise(); |
| 90 | |
| 91 | return NS_OK; |
| 92 | } |
| 93 | |
| 94 | NS_IMETHODIMPnsresult |
| 95 | StreamLoader::CheckListenerChain() { return NS_OK; } |
| 96 | |
| 97 | NS_IMETHODIMPnsresult |
| 98 | StreamLoader::OnStopRequest(nsIRequest* aRequest, nsresult aStatus) { |
| 99 | MOZ_ASSERT_IF(!StaticPrefs::network_send_OnDataFinished_cssLoader(),do { if (!StaticPrefs::network_send_OnDataFinished_cssLoader( )) { do { static_assert( mozilla::detail::AssertionConditionType <decltype(!mOnStopProcessingDone)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mOnStopProcessingDone))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("!mOnStopProcessingDone" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp" , 100); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mOnStopProcessingDone" ")"); do { *((volatile int*)__null) = 100; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false) |
| 100 | !mOnStopProcessingDone)do { if (!StaticPrefs::network_send_OnDataFinished_cssLoader( )) { do { static_assert( mozilla::detail::AssertionConditionType <decltype(!mOnStopProcessingDone)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!mOnStopProcessingDone))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("!mOnStopProcessingDone" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp" , 100); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mOnStopProcessingDone" ")"); do { *((volatile int*)__null) = 100; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); } } while ( false); |
| 101 | |
| 102 | // StreamLoader::OnStopRequest can get triggered twice for a request. |
| 103 | // Once from the path |
| 104 | // nsIThreadRetargetableStreamListener::OnDataFinished->StreamLoader::OnDataFinished |
| 105 | // (non-main thread) and |
| 106 | // once from nsIRequestObserver::OnStopRequest path (main thread). It is |
| 107 | // guaranteed that we will always get |
| 108 | // nsIThreadRetargetableStreamListener::OnDataFinished trigger first and this |
| 109 | // is always followed by nsIRequestObserver::OnStopRequest |
| 110 | |
| 111 | // If we are executing OnStopRequest OMT, we need to block resolution of parse |
| 112 | // promise and unblock again if we are executing this in main thread. |
| 113 | // Resolution of parse promise fires onLoadEvent and this should not happen |
| 114 | // before main thread OnStopRequest is dispatched. |
| 115 | if (NS_IsMainThread()) { |
| 116 | { |
| 117 | nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest); |
| 118 | channel->SetNotificationCallbacks(nullptr); |
| 119 | } |
| 120 | |
| 121 | mSheetLoadData->mNetworkMetadata = |
| 122 | new SubResourceNetworkMetadataHolder(aRequest); |
| 123 | |
| 124 | if (mOnDataFinishedTime) { |
| 125 | // collect telemetry for the delta between OnDataFinished and |
| 126 | // OnStopRequest |
| 127 | TimeDuration delta = (TimeStamp::Now() - mOnDataFinishedTime); |
| 128 | glean::networking::http_content_cssloader_ondatafinished_to_onstop_delay |
| 129 | .AccumulateRawDuration(delta); |
| 130 | } |
| 131 | mSheetLoadData->mSheet->UnblockParsePromise(); |
| 132 | } |
| 133 | |
| 134 | if (mOnStopProcessingDone) { |
| 135 | return NS_OK; |
| 136 | } |
| 137 | mOnStopProcessingDone = true; |
| 138 | |
| 139 | nsresult rv = mStatus; |
Value stored to 'rv' during its initialization is never read | |
| 140 | // Decoded data |
| 141 | nsCString utf8String; |
| 142 | { |
| 143 | nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest); |
| 144 | |
| 145 | if (NS_FAILED(mStatus)((bool)(__builtin_expect(!!(NS_FAILED_impl(mStatus)), 0)))) { |
| 146 | mSheetLoadData->VerifySheetReadyToParse(mStatus, ""_ns, ""_ns, channel, |
| 147 | mFinalChannelURI, |
| 148 | mChannelResultPrincipal); |
| 149 | |
| 150 | if (!NS_IsMainThread()) { |
| 151 | // When processing OMT, we have code paths in VerifySheetReadyToParse |
| 152 | // that are main-thread only. We bail on such scenarios and continue |
| 153 | // processing them on main thread OnStopRequest. |
| 154 | mOnStopProcessingDone = false; |
| 155 | } |
| 156 | return mStatus; |
| 157 | } |
| 158 | |
| 159 | rv = mSheetLoadData->VerifySheetReadyToParse(aStatus, mBOMBytes, mBytes, |
| 160 | channel, mFinalChannelURI, |
| 161 | mChannelResultPrincipal); |
| 162 | if (rv != NS_OK_PARSE_SHEET) { |
| 163 | if (!NS_IsMainThread()) { |
| 164 | mOnStopProcessingDone = false; |
| 165 | } |
| 166 | return rv; |
| 167 | } |
| 168 | |
| 169 | // At this point all the conditions that requires us to run on main |
| 170 | // are checked in VerifySheetReadyToParse |
| 171 | |
| 172 | // BOM detection generally happens during the write callback, but that |
| 173 | // won't have happened if fewer than three bytes were received. |
| 174 | if (mEncodingFromBOM.isNothing()) { |
| 175 | HandleBOM(); |
| 176 | MOZ_ASSERT(mEncodingFromBOM.isSome())do { static_assert( mozilla::detail::AssertionConditionType< decltype(mEncodingFromBOM.isSome())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mEncodingFromBOM.isSome()))) , 0))) { do { } while (false); MOZ_ReportAssertionFailure("mEncodingFromBOM.isSome()" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp" , 176); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mEncodingFromBOM.isSome()" ")"); do { *((volatile int*)__null) = 176; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 177 | } |
| 178 | // Hold the nsStringBuffer for the bytes from the stack to ensure release |
| 179 | // after its scope ends |
| 180 | nsCString bytes = std::move(mBytes); |
| 181 | // The BOM handling has happened, but we still may not have an encoding if |
| 182 | // there was no BOM. Ensure we have one. |
| 183 | const Encoding* encoding = mEncodingFromBOM.value(); |
| 184 | if (!encoding) { |
| 185 | // No BOM |
| 186 | encoding = mSheetLoadData->DetermineNonBOMEncoding(bytes, channel); |
| 187 | } |
| 188 | mSheetLoadData->mEncoding = encoding; |
| 189 | |
| 190 | size_t validated = 0; |
| 191 | if (encoding == UTF_8_ENCODING) { |
| 192 | validated = Encoding::UTF8ValidUpTo(bytes); |
| 193 | } |
| 194 | |
| 195 | if (validated == bytes.Length()) { |
| 196 | // Either this is UTF-8 and all valid, or it's not UTF-8 but is an empty |
| 197 | // string. This assumes that an empty string in any encoding decodes to |
| 198 | // empty string, which seems like a plausible assumption. |
| 199 | utf8String = std::move(bytes); |
| 200 | } else { |
| 201 | rv = encoding->DecodeWithoutBOMHandling(bytes, utf8String, validated); |
| 202 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp" , 202); return rv; } } while (false); |
| 203 | } |
| 204 | } // run destructor for `bytes` |
| 205 | |
| 206 | // For reasons I don't understand, factoring the below lines into |
| 207 | // a method on SheetLoadData resulted in a linker error. Hence, |
| 208 | // accessing fields of mSheetLoadData from here. |
| 209 | mSheetLoadData->mLoader->ParseSheet(utf8String, mMainThreadSheetLoadData, |
| 210 | Loader::AllowAsyncParse::Yes); |
| 211 | |
| 212 | mRequest = nullptr; |
| 213 | |
| 214 | return NS_OK; |
| 215 | } |
| 216 | |
| 217 | /* nsIStreamListener implementation */ |
| 218 | NS_IMETHODIMPnsresult |
| 219 | StreamLoader::OnDataAvailable(nsIRequest*, nsIInputStream* aInputStream, |
| 220 | uint64_t, uint32_t aCount) { |
| 221 | if (NS_FAILED(mStatus)((bool)(__builtin_expect(!!(NS_FAILED_impl(mStatus)), 0)))) { |
| 222 | return mStatus; |
| 223 | } |
| 224 | uint32_t dummy; |
| 225 | return aInputStream->ReadSegments(WriteSegmentFun, this, aCount, &dummy); |
| 226 | } |
| 227 | |
| 228 | void StreamLoader::HandleBOM() { |
| 229 | MOZ_ASSERT(mEncodingFromBOM.isNothing())do { static_assert( mozilla::detail::AssertionConditionType< decltype(mEncodingFromBOM.isNothing())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mEncodingFromBOM.isNothing() ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "mEncodingFromBOM.isNothing()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp" , 229); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mEncodingFromBOM.isNothing()" ")"); do { *((volatile int*)__null) = 229; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 230 | MOZ_ASSERT(mBytes.IsEmpty())do { static_assert( mozilla::detail::AssertionConditionType< decltype(mBytes.IsEmpty())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mBytes.IsEmpty()))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mBytes.IsEmpty()" , "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp" , 230); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mBytes.IsEmpty()" ")"); do { *((volatile int*)__null) = 230; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 231 | |
| 232 | auto [encoding, bomLength] = Encoding::ForBOM(mBOMBytes); |
| 233 | mEncodingFromBOM.emplace(encoding); // Null means no BOM. |
| 234 | |
| 235 | // BOMs are three bytes at most, but may be fewer. Copy over anything |
| 236 | // that wasn't part of the BOM to mBytes. Note that we need to track |
| 237 | // any BOM bytes as well for SRI handling. |
| 238 | mBytes.Append(Substring(mBOMBytes, bomLength)); |
| 239 | mBOMBytes.Truncate(bomLength); |
| 240 | } |
| 241 | |
| 242 | NS_IMETHODIMPnsresult |
| 243 | StreamLoader::OnDataFinished(nsresult aResult) { |
| 244 | if (StaticPrefs::network_send_OnDataFinished_cssLoader()) { |
| 245 | MOZ_ASSERT(mOnDataFinishedTime.IsNull(),do { static_assert( mozilla::detail::AssertionConditionType< decltype(mOnDataFinishedTime.IsNull())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mOnDataFinishedTime.IsNull() ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "mOnDataFinishedTime.IsNull()" " (" "OnDataFinished should only be called once" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp" , 246); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mOnDataFinishedTime.IsNull()" ") (" "OnDataFinished should only be called once" ")"); do { *((volatile int*)__null) = 246; __attribute__((nomerge)) ::abort (); } while (false); } } while (false) |
| 246 | "OnDataFinished should only be called once")do { static_assert( mozilla::detail::AssertionConditionType< decltype(mOnDataFinishedTime.IsNull())>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mOnDataFinishedTime.IsNull() ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "mOnDataFinishedTime.IsNull()" " (" "OnDataFinished should only be called once" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp" , 246); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mOnDataFinishedTime.IsNull()" ") (" "OnDataFinished should only be called once" ")"); do { *((volatile int*)__null) = 246; __attribute__((nomerge)) ::abort (); } while (false); } } while (false); |
| 247 | mOnDataFinishedTime = TimeStamp::Now(); |
| 248 | return OnStopRequest(mRequest, aResult); |
| 249 | } |
| 250 | |
| 251 | return NS_OK; |
| 252 | } |
| 253 | |
| 254 | NS_IMETHODIMPnsresult |
| 255 | StreamLoader::GetInterface(const nsIID& aIID, void** aResult) { |
| 256 | if (aIID.Equals(NS_GET_IID(nsIChannelEventSink)(nsIChannelEventSink::COMTypeInfo<nsIChannelEventSink, void >::kIID))) { |
| 257 | return QueryInterface(aIID, aResult); |
| 258 | } |
| 259 | |
| 260 | return NS_NOINTERFACE; |
| 261 | } |
| 262 | |
| 263 | nsresult StreamLoader::AsyncOnChannelRedirect( |
| 264 | nsIChannel* aOld, nsIChannel* aNew, uint32_t aFlags, |
| 265 | nsIAsyncVerifyRedirectCallback* aCallback) { |
| 266 | mSheetLoadData->SetMinimumExpirationTime( |
| 267 | nsContentUtils::GetSubresourceCacheExpirationTime(aOld, |
| 268 | mSheetLoadData->mURI)); |
| 269 | |
| 270 | aCallback->OnRedirectVerifyCallback(NS_OK); |
| 271 | |
| 272 | return NS_OK; |
| 273 | } |
| 274 | |
| 275 | nsresult StreamLoader::WriteSegmentFun(nsIInputStream*, void* aClosure, |
| 276 | const char* aSegment, uint32_t, |
| 277 | uint32_t aCount, uint32_t* aWriteCount) { |
| 278 | *aWriteCount = 0; |
| 279 | StreamLoader* self = static_cast<StreamLoader*>(aClosure); |
| 280 | if (NS_FAILED(self->mStatus)((bool)(__builtin_expect(!!(NS_FAILED_impl(self->mStatus)) , 0)))) { |
| 281 | return self->mStatus; |
| 282 | } |
| 283 | |
| 284 | // If we haven't done BOM detection yet, divert bytes into the special buffer. |
| 285 | if (self->mEncodingFromBOM.isNothing()) { |
| 286 | size_t bytesToCopy = std::min<size_t>(3 - self->mBOMBytes.Length(), aCount); |
| 287 | self->mBOMBytes.Append(aSegment, bytesToCopy); |
| 288 | aSegment += bytesToCopy; |
| 289 | *aWriteCount += bytesToCopy; |
| 290 | aCount -= bytesToCopy; |
| 291 | |
| 292 | if (self->mBOMBytes.Length() == 3) { |
| 293 | self->HandleBOM(); |
| 294 | } else { |
| 295 | return NS_OK; |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | if (!self->mBytes.Append(aSegment, aCount, fallible)) { |
| 300 | self->mBytes.Truncate(); |
| 301 | return (self->mStatus = NS_ERROR_OUT_OF_MEMORY); |
| 302 | } |
| 303 | |
| 304 | *aWriteCount += aCount; |
| 305 | return NS_OK; |
| 306 | } |
| 307 | |
| 308 | } // namespace mozilla::css |