Bug 1681529 - Part 11: Avoid using DelayedStart when serialzing the reply from SendOpenStream, r=asuth

Streams serialized with the default nsIInputStream serializer will be serialized
with delayedStart, meaning that when sent from the parent process to the content
process it will be serialized as a RemoteLazyInputStream.

In the specific case of SendOpenStream this causes issues, as the content
process code depends on the synchronous nature of nsIFileInputStream to allow it
to be wrapped in a SnappyUncompressInputStream, which requires a sync stream.

Relying on this property is not generally correct and only works because we know
only nsFileInputStream will be sent by the parent process. Other types of sync
streams may be received as async if they are sufficiently large, such as
nsStringInputStream.

Differential Revision: https://phabricator.services.mozilla.com/D103227
This commit is contained in:
Nika Layzell 2021-02-04 18:13:22 +00:00
Родитель daf01f9769
Коммит 6720e65c4e
3 изменённых файлов: 13 добавлений и 6 удалений

5
dom/cache/CacheStreamControlChild.cpp поставляемый
Просмотреть файл

@ -108,8 +108,9 @@ void CacheStreamControlChild::OpenStream(const nsID& aId,
SendOpenStream(aId)->Then(
GetCurrentSerialEventTarget(), __func__,
[aResolver,
holder = holder.clonePtr()](RefPtr<nsIInputStream>&& aOptionalStream) {
aResolver(nsCOMPtr<nsIInputStream>(std::move(aOptionalStream)));
holder = holder.clonePtr()](const Maybe<IPCStream>& aOptionalStream) {
nsCOMPtr<nsIInputStream> stream = DeserializeIPCStream(aOptionalStream);
aResolver(std::move(stream));
},
[aResolver, holder = holder.clonePtr()](ResponseRejectReason&& aReason) {
aResolver(nullptr);

10
dom/cache/CacheStreamControlParent.cpp поставляемый
Просмотреть файл

@ -109,8 +109,14 @@ mozilla::ipc::IPCResult CacheStreamControlParent::RecvOpenStream(
const nsID& aStreamId, OpenStreamResolver&& aResolver) {
NS_ASSERT_OWNINGTHREAD(CacheStreamControlParent);
OpenStream(aStreamId, [aResolver](nsCOMPtr<nsIInputStream>&& aStream) {
aResolver(aStream);
OpenStream(aStreamId, [aResolver, self = RefPtr{this}](
nsCOMPtr<nsIInputStream>&& aStream) {
AutoIPCStream autoStream;
if (self->CanSend() && autoStream.Serialize(aStream, self->Manager())) {
aResolver(autoStream.TakeOptionalValue());
} else {
aResolver(Nothing());
}
});
return IPC_OK();

4
dom/cache/PCacheStreamControl.ipdl поставляемый
Просмотреть файл

@ -6,9 +6,9 @@ include protocol PBackground;
include protocol PFileDescriptorSet;
include protocol PChildToParentStream;
include protocol PParentToChildStream;
include IPCStream;
using struct nsID from "nsID.h";
using refcounted class nsIInputStream from "mozilla/ipc/IPCStreamUtils.h";
namespace mozilla {
namespace dom {
@ -19,7 +19,7 @@ refcounted protocol PCacheStreamControl
manager PBackground;
parent:
async OpenStream(nsID aStreamId) returns(nsIInputStream aStream);
async OpenStream(nsID aStreamId) returns(IPCStream? aStream);
async NoteClosed(nsID aStreamId);
child: