Bug 1755032. Fix data race on imgRequest::mInnerWindowId. r=aosmond

Differential Revision: https://phabricator.services.mozilla.com/D138623
This commit is contained in:
Timothy Nikkel 2022-02-14 10:00:40 +00:00
parent 39ae6761a9
commit 6846d0c094
2 changed files with 18 additions and 9 deletions

View file

@ -57,7 +57,6 @@ imgRequest::imgRequest(imgLoader* aLoader, const ImageCacheKey& aCacheKey)
mLoadId(nullptr), mLoadId(nullptr),
mFirstProxy(nullptr), mFirstProxy(nullptr),
mValidator(nullptr), mValidator(nullptr),
mInnerWindowId(0),
mCORSMode(CORS_NONE), mCORSMode(CORS_NONE),
mImageErrorCode(NS_OK), mImageErrorCode(NS_OK),
mImageAvailable(false), mImageAvailable(false),
@ -65,6 +64,7 @@ imgRequest::imgRequest(imgLoader* aLoader, const ImageCacheKey& aCacheKey)
mIsCrossSiteNoCORSRequest(false), mIsCrossSiteNoCORSRequest(false),
mMutex("imgRequest"), mMutex("imgRequest"),
mProgressTracker(new ProgressTracker()), mProgressTracker(new ProgressTracker()),
mInnerWindowId(0),
mIsMultiPartChannel(false), mIsMultiPartChannel(false),
mIsInCache(false), mIsInCache(false),
mDecodeRequested(false), mDecodeRequested(false),
@ -276,6 +276,16 @@ nsresult imgRequest::RemoveProxy(imgRequestProxy* proxy, nsresult aStatus) {
return NS_OK; return NS_OK;
} }
uint64_t imgRequest::InnerWindowID() const {
MutexAutoLock lock(mMutex);
return mInnerWindowId;
}
void imgRequest::SetInnerWindowID(uint64_t aInnerWindowId) {
MutexAutoLock lock(mMutex);
mInnerWindowId = aInnerWindowId;
}
void imgRequest::CancelAndAbort(nsresult aStatus) { void imgRequest::CancelAndAbort(nsresult aStatus) {
LOG_SCOPE(gImgLog, "imgRequest::CancelAndAbort"); LOG_SCOPE(gImgLog, "imgRequest::CancelAndAbort");
@ -960,6 +970,7 @@ imgRequest::OnDataAvailable(nsIRequest* aRequest, nsIInputStream* aInStr,
RefPtr<ProgressTracker> progressTracker; RefPtr<ProgressTracker> progressTracker;
bool isMultipart = false; bool isMultipart = false;
bool newPartPending = false; bool newPartPending = false;
uint64_t innerWindowId = 0;
// Retrieve and update our state. // Retrieve and update our state.
{ {
@ -969,6 +980,7 @@ imgRequest::OnDataAvailable(nsIRequest* aRequest, nsIInputStream* aInStr,
isMultipart = mIsMultiPartChannel; isMultipart = mIsMultiPartChannel;
newPartPending = mNewPartPending; newPartPending = mNewPartPending;
mNewPartPending = false; mNewPartPending = false;
innerWindowId = mInnerWindowId;
} }
// If this is a new part, we need to sniff its content type and create an // If this is a new part, we need to sniff its content type and create an
@ -976,7 +988,7 @@ imgRequest::OnDataAvailable(nsIRequest* aRequest, nsIInputStream* aInStr,
if (newPartPending) { if (newPartPending) {
NewPartResult result = NewPartResult result =
PrepareForNewPart(aRequest, aInStr, aCount, mURI, isMultipart, image, PrepareForNewPart(aRequest, aInStr, aCount, mURI, isMultipart, image,
progressTracker, mInnerWindowId); progressTracker, innerWindowId);
bool succeeded = result.mSucceeded; bool succeeded = result.mSucceeded;
if (result.mImage) { if (result.mImage) {

View file

@ -95,10 +95,8 @@ class imgRequest final : public nsIStreamListener,
// Request that we start decoding the image as soon as data becomes available. // Request that we start decoding the image as soon as data becomes available.
void StartDecoding(); void StartDecoding();
inline uint64_t InnerWindowID() const { return mInnerWindowId; } uint64_t InnerWindowID() const;
void SetInnerWindowID(uint64_t aInnerWindowId) { void SetInnerWindowID(uint64_t aInnerWindowId);
mInnerWindowId = aInnerWindowId;
}
// Set the cache validation information (expiry time, whether we must // Set the cache validation information (expiry time, whether we must
// validate, etc) on the cache entry based on the request information. // validate, etc) on the cache entry based on the request information.
@ -263,9 +261,6 @@ class imgRequest final : public nsIStreamListener,
nsCOMPtr<nsIAsyncVerifyRedirectCallback> mRedirectCallback; nsCOMPtr<nsIAsyncVerifyRedirectCallback> mRedirectCallback;
nsCOMPtr<nsIChannel> mNewRedirectChannel; nsCOMPtr<nsIChannel> mNewRedirectChannel;
// The ID of the inner window origin, used for error reporting.
uint64_t mInnerWindowId;
// The CORS mode (defined in imgIRequest) this image was loaded with. By // The CORS mode (defined in imgIRequest) this image was loaded with. By
// default, CORS_NONE. // default, CORS_NONE.
mozilla::CORSMode mCORSMode; mozilla::CORSMode mCORSMode;
@ -290,6 +285,8 @@ class imgRequest final : public nsIStreamListener,
// must not be a part of this bitfield. // must not be a part of this bitfield.
RefPtr<ProgressTracker> mProgressTracker; RefPtr<ProgressTracker> mProgressTracker;
RefPtr<Image> mImage; RefPtr<Image> mImage;
// The ID of the inner window origin, used for error reporting, profiles.
uint64_t mInnerWindowId;
bool mIsMultiPartChannel : 1; bool mIsMultiPartChannel : 1;
bool mIsInCache : 1; bool mIsInCache : 1;
bool mDecodeRequested : 1; bool mDecodeRequested : 1;