Bug 1681529 - Part 7: Wrap the inner streams in a nsMIMEInputStream to make them seekable, r=baku,necko-reviewers,dragana

nsMIMEInputStream has a requirement that the inner nsIInputStream object
implement nsISeekableStream, which is usually enforced by the SetData method.
This check was bypassed by the Deserialize method, which unfortunately meant
that non-seekable IPC payloads could end up within a nsMIMEInputStream when sent
from another process (e.g. due to large nsStringStreams being serialized as
nsPipes over IPC).

This patch uses the SeekableStreamWrapper introduced in the previous patch to
wrap the inner stream when deserializing nsMIMEInputStream, avoiding the
previously mentioned issue.

Differential Revision: https://phabricator.services.mozilla.com/D101806
This commit is contained in:
Nika Layzell 2021-01-27 21:55:19 +00:00
parent 96b1095085
commit 55c9ceedc7

View File

@ -14,6 +14,7 @@
#include "ipc/IPCMessageUtils.h"
#include "mozilla/Mutex.h"
#include "mozilla/SeekableStreamWrapper.h"
#include "mozilla/ipc/InputStreamUtils.h"
#include "nsCOMPtr.h"
#include "nsComponentManagerUtils.h"
@ -415,7 +416,18 @@ bool nsMIMEInputStream::Deserialize(
return false;
}
mStream = stream;
// nsMIMEInputStream requires that the underlying data stream be seekable,
// as is checked in `SetData`. Ensure that the stream we deserialized is
// seekable before using it.
nsCOMPtr<nsIInputStream> seekable;
nsresult rv = mozilla::SeekableStreamWrapper::MaybeWrap(
stream.forget(), getter_AddRefs(seekable));
if (NS_FAILED(rv)) {
NS_WARNING("Failed to ensure wrapped input stream is seekable");
return false;
}
MOZ_ALWAYS_SUCCEEDS(SetData(seekable));
}
return true;