Bug Summary

File:var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp
Warning:line 136, column 12
Value stored to 'rv' during its initialization is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name Unified_cpp_layout_style3.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/layout/style -fcoverage-compilation-dir=/var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/layout/style -resource-dir /usr/lib/llvm-18/lib/clang/18 -include /var/lib/jenkins/workspace/firefox-scan-build/config/gcc_hidden.h -include /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/mozilla-config.h -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/stl_wrappers -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/system_wrappers -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG=1 -D MOZ_HAS_MOZGLUE -D MOZILLA_INTERNAL_API -D IMPL_LIBXUL -D STATIC_EXPORTABLE_JS_API -I /var/lib/jenkins/workspace/firefox-scan-build/layout/style -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/layout/style -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/ipc/ipdl/_ipdlheaders -I /var/lib/jenkins/workspace/firefox-scan-build/ipc/chromium/src -I /var/lib/jenkins/workspace/firefox-scan-build/layout/base -I /var/lib/jenkins/workspace/firefox-scan-build/layout/generic -I /var/lib/jenkins/workspace/firefox-scan-build/layout/xul -I /var/lib/jenkins/workspace/firefox-scan-build/dom/base -I /var/lib/jenkins/workspace/firefox-scan-build/dom/html -I /var/lib/jenkins/workspace/firefox-scan-build/dom/xul -I /var/lib/jenkins/workspace/firefox-scan-build/image -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/x86_64-linux-gnu/c++/13 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/backward -internal-isystem /usr/lib/llvm-18/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-error=tautological-type-limit-compare -Wno-invalid-offsetof -Wno-range-loop-analysis -Wno-deprecated-anon-enum-enum-conversion -Wno-deprecated-enum-enum-conversion -Wno-deprecated-this-capture -Wno-inline-new-delete -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-vla-cxx-extension -Wno-unknown-warning-option -fdeprecated-macro -ferror-limit 19 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fno-rtti -fgnuc-version=4.2.1 -fno-aligned-allocation -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2024-05-16-034744-15991-1 -x c++ Unified_cpp_layout_style3.cpp
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 "nsContentUtils.h"
13#include "nsIChannel.h"
14#include "nsIInputStream.h"
15#include "nsIThreadRetargetableRequest.h"
16#include "nsIStreamTransportService.h"
17#include "nsNetCID.h"
18#include "nsNetUtil.h"
19#include "nsProxyRelease.h"
20#include "nsServiceManagerUtils.h"
21
22namespace mozilla::css {
23
24StreamLoader::StreamLoader(SheetLoadData& aSheetLoadData)
25 : mSheetLoadData(&aSheetLoadData),
26 mStatus(NS_OK),
27 mMainThreadSheetLoadData(new nsMainThreadPtrHolder<SheetLoadData>(
28 "StreamLoader::SheetLoadData", mSheetLoadData, false)) {}
29
30StreamLoader::~StreamLoader() {
31#ifdef NIGHTLY_BUILD1
32 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"
, 32); AnnotateMozCrashReason("MOZ_RELEASE_ASSERT" "(" "mOnStopProcessingDone || mChannelOpenFailed"
")"); do { *((volatile int*)__null) = 32; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
33#endif
34}
35
36NS_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"
, 37); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0"
") (" "illegal refcnt" ")"); do { *((volatile int*)__null) =
37; __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"
, 37); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"StreamLoader\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 37; __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"
, 37); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0"
") (" "dup release" ")"); do { *((volatile int*)__null) = 37
; __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"
, 37); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"StreamLoader\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 37; __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"
, 37); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE
; static_assert(2 > 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, nsISupports>, int32_t(reinterpret_cast<
char*>(static_cast<nsISupports*>( static_cast<nsIStreamListener
*>((StreamLoader*)0x1000))) - reinterpret_cast<char*>
((StreamLoader*)0x1000))}, { nullptr, 0 } } ; static_assert((
sizeof(table) / sizeof(table[0])) > 1, "need at least 1 interface"
); rv = NS_TableDrivenQI(static_cast<void*>(this), aIID
, aInstancePtr, table); return rv; }
37 nsIThreadRetargetableStreamListener)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"
, 37); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0"
") (" "illegal refcnt" ")"); do { *((volatile int*)__null) =
37; __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"
, 37); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"StreamLoader\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 37; __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"
, 37); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0"
") (" "dup release" ")"); do { *((volatile int*)__null) = 37
; __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"
, 37); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"StreamLoader\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 37; __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"
, 37); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE
; static_assert(2 > 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, nsISupports>, int32_t(reinterpret_cast<
char*>(static_cast<nsISupports*>( static_cast<nsIStreamListener
*>((StreamLoader*)0x1000))) - reinterpret_cast<char*>
((StreamLoader*)0x1000))}, { nullptr, 0 } } ; static_assert((
sizeof(table) / sizeof(table[0])) > 1, "need at least 1 interface"
); rv = NS_TableDrivenQI(static_cast<void*>(this), aIID
, aInstancePtr, table); return rv; }
38
39/* nsIRequestObserver implementation */
40NS_IMETHODIMPnsresult
41StreamLoader::OnStartRequest(nsIRequest* aRequest) {
42 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"
, 42); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aRequest" ")"
); do { *((volatile int*)__null) = 42; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
43 mRequest = aRequest;
44 mSheetLoadData->NotifyStart(aRequest);
45
46 // It's kinda bad to let Web content send a number that results
47 // in a potentially large allocation directly, but efficiency of
48 // compression bombs is so great that it doesn't make much sense
49 // to require a site to send one before going ahead and allocating.
50 if (nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest)) {
51 int64_t length;
52 nsresult rv = channel->GetContentLength(&length);
53 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && length > 0) {
54 CheckedInt<nsACString::size_type> checkedLength(length);
55 if (!checkedLength.isValid()) {
56 return (mStatus = NS_ERROR_OUT_OF_MEMORY);
57 }
58 if (!mBytes.SetCapacity(checkedLength.value(), fallible)) {
59 return (mStatus = NS_ERROR_OUT_OF_MEMORY);
60 }
61 }
62 NS_GetFinalChannelURI(channel, getter_AddRefs(mFinalChannelURI));
63 nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
64 // we dont return on error here as the error is handled in
65 // SheetLoadData::VerifySheetReadyToParse
66 Unused << secMan->GetChannelResultPrincipal(
67 channel, getter_AddRefs(mChannelResultPrincipal));
68 }
69 if (nsCOMPtr<nsIThreadRetargetableRequest> rr = do_QueryInterface(aRequest)) {
70 nsCOMPtr<nsIEventTarget> sts =
71 do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID"@mozilla.org/network/stream-transport-service;1");
72 RefPtr queue =
73 TaskQueue::Create(sts.forget(), "css::StreamLoader Delivery Queue");
74 rr->RetargetDeliveryTo(queue);
75 }
76
77 mSheetLoadData->mExpirationTime = [&] {
78 auto info = nsContentUtils::GetSubresourceCacheValidationInfo(
79 aRequest, mSheetLoadData->mURI);
80
81 // For now, we never cache entries that we have to revalidate, or whose
82 // channel don't support caching.
83 if (info.mMustRevalidate || !info.mExpirationTime) {
84 return nsContentUtils::SecondsFromPRTime(PR_Now()) - 1;
85 }
86 return *info.mExpirationTime;
87 }();
88
89 // We need to block block resolution of parse promise until we receive
90 // OnStopRequest on Main thread. This is necessary because parse promise
91 // resolution fires OnLoad event OnLoad event must not be dispatched until
92 // OnStopRequest in main thread is processed, for stuff like performance
93 // resource entries.
94 mSheetLoadData->mSheet->BlockParsePromise();
95
96 return NS_OK;
97}
98
99NS_IMETHODIMPnsresult
100StreamLoader::CheckListenerChain() { return NS_OK; }
101
102NS_IMETHODIMPnsresult
103StreamLoader::OnStopRequest(nsIRequest* aRequest, nsresult aStatus) {
104 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"
, 105); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mOnStopProcessingDone"
")"); do { *((volatile int*)__null) = 105; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
105 !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"
, 105); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mOnStopProcessingDone"
")"); do { *((volatile int*)__null) = 105; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
;
106
107 // StreamLoader::OnStopRequest can get triggered twice for a request.
108 // Once from the path
109 // nsIThreadRetargetableStreamListener::OnDataFinished->StreamLoader::OnDataFinished
110 // (non-main thread) and
111 // once from nsIRequestObserver::OnStopRequest path (main thread). It is
112 // guaranteed that we will always get
113 // nsIThreadRetargetableStreamListener::OnDataFinished trigger first and this
114 // is always followed by nsIRequestObserver::OnStopRequest
115
116 // If we are executing OnStopRequest OMT, we need to block resolution of parse
117 // promise and unblock again if we are executing this in main thread.
118 // Resolution of parse promise fires onLoadEvent and this should not happen
119 // before main thread OnStopRequest is dispatched.
120 if (NS_IsMainThread()) {
121 if (mOnDataFinishedTime) {
122 // collect telemetry for the delta between OnDataFinished and
123 // OnStopRequest
124 TimeDuration delta = (TimeStamp::Now() - mOnDataFinishedTime);
125 glean::networking::http_content_cssloader_ondatafinished_to_onstop_delay
126 .AccumulateRawDuration(delta);
127 }
128 mSheetLoadData->mSheet->UnblockParsePromise();
129 }
130
131 if (mOnStopProcessingDone) {
132 return NS_OK;
133 }
134 mOnStopProcessingDone = true;
135
136 nsresult rv = mStatus;
Value stored to 'rv' during its initialization is never read
137 // Decoded data
138 nsCString utf8String;
139 {
140 nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
141
142 if (NS_FAILED(mStatus)((bool)(__builtin_expect(!!(NS_FAILED_impl(mStatus)), 0)))) {
143 mSheetLoadData->VerifySheetReadyToParse(mStatus, ""_ns, ""_ns, channel,
144 mFinalChannelURI,
145 mChannelResultPrincipal);
146
147 if (!NS_IsMainThread()) {
148 // When processing OMT, we have code paths in VerifySheetReadyToParse
149 // that are main-thread only. We bail on such scenarios and continue
150 // processing them on main thread OnStopRequest.
151 mOnStopProcessingDone = false;
152 }
153 return mStatus;
154 }
155
156 rv = mSheetLoadData->VerifySheetReadyToParse(aStatus, mBOMBytes, mBytes,
157 channel, mFinalChannelURI,
158 mChannelResultPrincipal);
159 if (rv != NS_OK_PARSE_SHEET) {
160 if (!NS_IsMainThread()) {
161 mOnStopProcessingDone = false;
162 }
163 return rv;
164 }
165
166 // At this point all the conditions that requires us to run on main
167 // are checked in VerifySheetReadyToParse
168
169 // BOM detection generally happens during the write callback, but that
170 // won't have happened if fewer than three bytes were received.
171 if (mEncodingFromBOM.isNothing()) {
172 HandleBOM();
173 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"
, 173); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mEncodingFromBOM.isSome()"
")"); do { *((volatile int*)__null) = 173; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
174 }
175 // Hold the nsStringBuffer for the bytes from the stack to ensure release
176 // after its scope ends
177 nsCString bytes = std::move(mBytes);
178 // The BOM handling has happened, but we still may not have an encoding if
179 // there was no BOM. Ensure we have one.
180 const Encoding* encoding = mEncodingFromBOM.value();
181 if (!encoding) {
182 // No BOM
183 encoding = mSheetLoadData->DetermineNonBOMEncoding(bytes, channel);
184 }
185 mSheetLoadData->mEncoding = encoding;
186
187 size_t validated = 0;
188 if (encoding == UTF_8_ENCODING) {
189 validated = Encoding::UTF8ValidUpTo(bytes);
190 }
191
192 if (validated == bytes.Length()) {
193 // Either this is UTF-8 and all valid, or it's not UTF-8 but is an empty
194 // string. This assumes that an empty string in any encoding decodes to
195 // empty string, which seems like a plausible assumption.
196 utf8String = std::move(bytes);
197 } else {
198 rv = encoding->DecodeWithoutBOMHandling(bytes, utf8String, validated);
199 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"
, 199); return rv; } } while (false)
;
200 }
201 } // run destructor for `bytes`
202
203 // For reasons I don't understand, factoring the below lines into
204 // a method on SheetLoadData resulted in a linker error. Hence,
205 // accessing fields of mSheetLoadData from here.
206 mSheetLoadData->mLoader->ParseSheet(utf8String, mMainThreadSheetLoadData,
207 Loader::AllowAsyncParse::Yes);
208
209 mRequest = nullptr;
210
211 return NS_OK;
212}
213
214/* nsIStreamListener implementation */
215NS_IMETHODIMPnsresult
216StreamLoader::OnDataAvailable(nsIRequest*, nsIInputStream* aInputStream,
217 uint64_t, uint32_t aCount) {
218 if (NS_FAILED(mStatus)((bool)(__builtin_expect(!!(NS_FAILED_impl(mStatus)), 0)))) {
219 return mStatus;
220 }
221 uint32_t dummy;
222 return aInputStream->ReadSegments(WriteSegmentFun, this, aCount, &dummy);
223}
224
225void StreamLoader::HandleBOM() {
226 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"
, 226); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mEncodingFromBOM.isNothing()"
")"); do { *((volatile int*)__null) = 226; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
227 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"
, 227); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mBytes.IsEmpty()"
")"); do { *((volatile int*)__null) = 227; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
228
229 auto [encoding, bomLength] = Encoding::ForBOM(mBOMBytes);
230 mEncodingFromBOM.emplace(encoding); // Null means no BOM.
231
232 // BOMs are three bytes at most, but may be fewer. Copy over anything
233 // that wasn't part of the BOM to mBytes. Note that we need to track
234 // any BOM bytes as well for SRI handling.
235 mBytes.Append(Substring(mBOMBytes, bomLength));
236 mBOMBytes.Truncate(bomLength);
237}
238
239NS_IMETHODIMPnsresult
240StreamLoader::OnDataFinished(nsresult aResult) {
241 if (StaticPrefs::network_send_OnDataFinished_cssLoader()) {
242 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"
, 243); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mOnDataFinishedTime.IsNull()"
") (" "OnDataFinished should only be called once" ")"); do {
*((volatile int*)__null) = 243; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
243 "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"
, 243); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mOnDataFinishedTime.IsNull()"
") (" "OnDataFinished should only be called once" ")"); do {
*((volatile int*)__null) = 243; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
;
244 mOnDataFinishedTime = TimeStamp::Now();
245 return OnStopRequest(mRequest, aResult);
246 }
247
248 return NS_OK;
249}
250
251nsresult StreamLoader::WriteSegmentFun(nsIInputStream*, void* aClosure,
252 const char* aSegment, uint32_t,
253 uint32_t aCount, uint32_t* aWriteCount) {
254 *aWriteCount = 0;
255 StreamLoader* self = static_cast<StreamLoader*>(aClosure);
256 if (NS_FAILED(self->mStatus)((bool)(__builtin_expect(!!(NS_FAILED_impl(self->mStatus))
, 0)))
) {
257 return self->mStatus;
258 }
259
260 // If we haven't done BOM detection yet, divert bytes into the special buffer.
261 if (self->mEncodingFromBOM.isNothing()) {
262 size_t bytesToCopy = std::min<size_t>(3 - self->mBOMBytes.Length(), aCount);
263 self->mBOMBytes.Append(aSegment, bytesToCopy);
264 aSegment += bytesToCopy;
265 *aWriteCount += bytesToCopy;
266 aCount -= bytesToCopy;
267
268 if (self->mBOMBytes.Length() == 3) {
269 self->HandleBOM();
270 } else {
271 return NS_OK;
272 }
273 }
274
275 if (!self->mBytes.Append(aSegment, aCount, fallible)) {
276 self->mBytes.Truncate();
277 return (self->mStatus = NS_ERROR_OUT_OF_MEMORY);
278 }
279
280 *aWriteCount += aCount;
281 return NS_OK;
282}
283
284} // namespace mozilla::css