From 45ebc1fdb7893f3be1109b53e53e1e3fc1001c85 Mon Sep 17 00:00:00 2001 From: Kelsey Gilbert Date: Sat, 27 Jul 2024 22:40:39 +0000 Subject: [PATCH] Bug 1885245 - Remove PlainOldDataSerializer. r=mccr8 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 --- ipc/glue/IPCMessageUtils.h | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/ipc/glue/IPCMessageUtils.h b/ipc/glue/IPCMessageUtils.h index cdcd3c574a60..22faac9cf95e 100644 --- a/ipc/glue/IPCMessageUtils.h +++ b/ipc/glue/IPCMessageUtils.h @@ -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 from PlainOldDataSerializer 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 -struct PlainOldDataSerializer { - static_assert( - std::is_trivially_copyable::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.