Commit 115d41f5 authored by Ken Rockot's avatar Ken Rockot Committed by Commit Bot

Ignore soft message size limits on Serialize calls

Application code may call mojom structs' generated Serialize() method to
produce a local array of bytes representing the serialized object. These
methods ultimately use the same message serialization logic that applies
to IPC messages.

Soft size limit checks are done during the serialization process, and so
manual Serialize calls can still trigger crash dumps when serializing
very large objects.

Since the intent of the checks is to reveal oversized IPC messages for
performance reasons, there's no reason to apply them on these Serialize
calls.

This CL modifies the common path used by all generated Serialize()
methods to ensure that the size checks are bypassed.

Bug: 1141987
Change-Id: I936ba58cf682c4b63310f746cd19a933c82a70b2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2495835Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Ken Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#821060}
parent a4256166
...@@ -63,7 +63,11 @@ struct MojomSerializationImplTraits< ...@@ -63,7 +63,11 @@ struct MojomSerializationImplTraits<
template <typename MojomType, typename UserType> template <typename MojomType, typename UserType>
mojo::Message SerializeAsMessageImpl(UserType* input) { mojo::Message SerializeAsMessageImpl(UserType* input) {
SerializationContext context; SerializationContext context;
mojo::Message message(0, 0, 0, 0, nullptr); // Note that this is only called by application code serializing a structure
// manually (e.g. for storage). As such we don't want Mojo's soft message size
// limits to be applied.
mojo::Message message(0, 0, 0, 0, MOJO_CREATE_MESSAGE_FLAG_UNLIMITED_SIZE,
nullptr);
typename MojomTypeTraits<MojomType>::Data::BufferWriter writer; typename MojomTypeTraits<MojomType>::Data::BufferWriter writer;
MojomSerializationImplTraits<MojomType>::Serialize( MojomSerializationImplTraits<MojomType>::Serialize(
*input, message.payload_buffer(), &writer, &context); *input, message.payload_buffer(), &writer, &context);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment