forked from mirrors/gecko-dev
Bug 1885245 - Remove PlainOldDataSerializer. r=mccr8 a=RyanVM
There's no sufficiently robust way to identify POD types in C++, such that we could rely on this kind of thing for serialization. As one example, `bool` must be carefully handled on deserialize, in case an attacker wants to exploit the UB of bool with value 2. Additionally, generally it's not viable to tell whether all the members of a struct are PODs as well, and we need that level of assurance recursively! So we instead lean on e.g. ParamTraits_TiedFields/_IsEnumCase for our extreme robustness requirements. Differential Revision: https://phabricator.services.mozilla.com/D217518
This commit is contained in:
parent
04c64b338a
commit
2b8bf0f71d
1 changed files with 0 additions and 30 deletions
|
|
@ -47,36 +47,6 @@ struct VariantTag;
|
|||
|
||||
namespace IPC {
|
||||
|
||||
/**
|
||||
* A helper class for serializing plain-old data (POD) structures.
|
||||
* The memory representation of the structure is written to and read from
|
||||
* the serialized stream directly, without individual processing of the
|
||||
* structure's members.
|
||||
*
|
||||
* Derive ParamTraits<T> from PlainOldDataSerializer<T> if T is POD.
|
||||
*
|
||||
* Note: For POD structures with enumeration fields, this will not do
|
||||
* validation of the enum values the way serializing the fields
|
||||
* individually would. Prefer serializing the fields individually
|
||||
* in such cases.
|
||||
*/
|
||||
template <typename T>
|
||||
struct PlainOldDataSerializer {
|
||||
static_assert(
|
||||
std::is_trivially_copyable<T>::value,
|
||||
"PlainOldDataSerializer can only be used with trivially copyable types!");
|
||||
|
||||
typedef T paramType;
|
||||
|
||||
static void Write(MessageWriter* aWriter, const paramType& aParam) {
|
||||
aWriter->WriteBytes(&aParam, sizeof(aParam));
|
||||
}
|
||||
|
||||
static bool Read(MessageReader* aReader, paramType* aResult) {
|
||||
return aReader->ReadBytesInto(aResult, sizeof(paramType));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* A helper class for serializing empty structs. Since the struct is empty there
|
||||
* is nothing to write, and a priori we know the result of the read.
|
||||
|
|
|
|||
Loading…
Reference in a new issue