From 05329884590b2dec2c13248be5641177f2e80882 Mon Sep 17 00:00:00 2001 From: Nika Layzell Date: Mon, 2 May 2022 20:44:23 +0000 Subject: [PATCH] Bug 1754004 - Part 5: Only implement nsISeekableStream on nsBufferedStreams if it's implemented by the underlying stream, r=asuth,necko-reviewers,dragana Previously, nsBufferedStreams would always implement nsISeekableStream, whether or not the underlying stream did, and would only fail when trying to seek. This makes it much more difficult to compensate and correctly transform streams when they need to be seekable. Differential Revision: https://phabricator.services.mozilla.com/D141042 --- netwerk/base/nsBufferedStreams.cpp | 11 ++++++++++- netwerk/base/nsBufferedStreams.h | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/netwerk/base/nsBufferedStreams.cpp b/netwerk/base/nsBufferedStreams.cpp index eb90284c2f72..4241338fee52 100644 --- a/netwerk/base/nsBufferedStreams.cpp +++ b/netwerk/base/nsBufferedStreams.cpp @@ -50,7 +50,14 @@ using mozilla::Some; nsBufferedStream::~nsBufferedStream() { Close(); } -NS_IMPL_ISUPPORTS(nsBufferedStream, nsITellableStream, nsISeekableStream) +NS_IMPL_ADDREF(nsBufferedStream) +NS_IMPL_RELEASE(nsBufferedStream) + +NS_INTERFACE_MAP_BEGIN(nsBufferedStream) + NS_INTERFACE_MAP_ENTRY(nsISupports) + NS_INTERFACE_MAP_ENTRY(nsITellableStream) + NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsISeekableStream, mSeekable) +NS_INTERFACE_MAP_END nsresult nsBufferedStream::Init(nsISupports* aStream, uint32_t bufferSize) { NS_ASSERTION(aStream, "need to supply a stream"); @@ -59,6 +66,8 @@ nsresult nsBufferedStream::Init(nsISupports* aStream, uint32_t bufferSize) { mBufferSize = bufferSize; mBufferStartOffset = 0; mCursor = 0; + nsCOMPtr seekable = do_QueryInterface(mStream); + mSeekable = seekable; mBuffer = new (mozilla::fallible) char[bufferSize]; if (mBuffer == nullptr) { return NS_ERROR_OUT_OF_MEMORY; diff --git a/netwerk/base/nsBufferedStreams.h b/netwerk/base/nsBufferedStreams.h index 241ca8593a67..50ac76b72b6c 100644 --- a/netwerk/base/nsBufferedStreams.h +++ b/netwerk/base/nsBufferedStreams.h @@ -58,6 +58,7 @@ class nsBufferedStream : public nsISeekableStream { bool mBufferDisabled{false}; bool mEOF{false}; // True if mStream is at EOF + bool mSeekable{true}; uint8_t mGetBufferCount{0}; };