Bug 1633197 - WebSocket bufferedAmount must be unsigned long long (uint64_t), r=valentin

Differential Revision: https://phabricator.services.mozilla.com/D74558
This commit is contained in:
Andrea Marchesini
2020-05-11 07:44:10 +00:00
parent c2b625434c
commit 82200df343
3 changed files with 19 additions and 11 deletions

View File

@@ -31,7 +31,7 @@ interface WebSocket : EventTarget {
readonly attribute unsigned short readyState;
readonly attribute unsigned long bufferedAmount;
readonly attribute unsigned long long bufferedAmount;
// networking

View File

@@ -789,11 +789,15 @@ WebSocketImpl::OnAcknowledge(nsISupports* aContext, uint32_t aSize) {
return NS_ERROR_UNEXPECTED;
}
mWebSocket->mOutgoingBufferedAmount -= aSize;
if (!mWebSocket->mOutgoingBufferedAmount.isValid()) {
CheckedUint64 outgoingBufferedAmount = mWebSocket->mOutgoingBufferedAmount;
outgoingBufferedAmount -= aSize;
if (!outgoingBufferedAmount.isValid()) {
return NS_ERROR_UNEXPECTED;
}
mWebSocket->mOutgoingBufferedAmount = outgoingBufferedAmount;
MOZ_RELEASE_ASSERT(mWebSocket->mOutgoingBufferedAmount.isValid());
return NS_OK;
}
@@ -2199,8 +2203,8 @@ void WebSocket::SetReadyState(uint16_t aReadyState) {
mReadyState = aReadyState;
}
// webIDL: readonly attribute unsigned long bufferedAmount;
uint32_t WebSocket::BufferedAmount() const {
// webIDL: readonly attribute unsigned long long bufferedAmount;
uint64_t WebSocket::BufferedAmount() const {
AssertIsOnTargetThread();
MOZ_RELEASE_ASSERT(mOutgoingBufferedAmount.isValid());
return mOutgoingBufferedAmount.value();
@@ -2309,13 +2313,17 @@ void WebSocket::Send(nsIInputStream* aMsgStream, const nsACString& aMsgString,
return;
}
// Always increment outgoing buffer len, even if closed
mOutgoingBufferedAmount += aMsgLength;
if (!mOutgoingBufferedAmount.isValid()) {
CheckedUint64 outgoingBufferedAmount = mOutgoingBufferedAmount;
outgoingBufferedAmount += aMsgLength;
if (!outgoingBufferedAmount.isValid()) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return;
}
// Always increment outgoing buffer len, even if closed
mOutgoingBufferedAmount = outgoingBufferedAmount;
MOZ_RELEASE_ASSERT(mOutgoingBufferedAmount.isValid());
if (readyState == CLOSING || readyState == CLOSED) {
return;
}

View File

@@ -104,8 +104,8 @@ class WebSocket final : public DOMEventTargetHelper {
// webIDL: readonly attribute unsigned short readyState;
uint16_t ReadyState();
// webIDL: readonly attribute unsigned long bufferedAmount;
uint32_t BufferedAmount() const;
// webIDL: readonly attribute unsigned long long bufferedAmount;
uint64_t BufferedAmount() const;
// webIDL: attribute Function? onopen;
IMPL_EVENT_HANDLER(open)
@@ -179,7 +179,7 @@ class WebSocket final : public DOMEventTargetHelper {
bool mKeepingAlive;
bool mCheckMustKeepAlive;
CheckedUint32 mOutgoingBufferedAmount;
CheckedUint64 mOutgoingBufferedAmount;
// related to the WebSocket constructor steps
nsString mURI;