1// Copyright 2016 The Fuchsia Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "struct.h" 6 7#include <stdint.h> 8 9_Static_assert(sizeof(mojo_struct_header_t) == 8u, "mojo_struct_header_t should be 8 bytes"); 10 11bool mojo_validate_struct_header(const void* data, size_t size) { 12 if (size < sizeof(mojo_struct_header_t) || size > UINT32_MAX) { 13 return false; 14 } 15 16 const mojo_struct_header_t* header = (const mojo_struct_header_t*)data; 17 18 if (header->num_bytes < sizeof(mojo_struct_header_t) || header->num_bytes > size) { 19 return false; 20 } 21 22 return true; 23} 24