514 lines
17 KiB
C++
Executable File
514 lines
17 KiB
C++
Executable File
// Copyright 2016 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#if defined(_MSC_VER)
|
|
#pragma warning(push)
|
|
#pragma warning(disable:4065)
|
|
#endif
|
|
|
|
#include "components/spellcheck/common/spellcheck.mojom-shared.h"
|
|
|
|
#include <utility>
|
|
|
|
#include "base/logging.h"
|
|
#include "mojo/public/cpp/bindings/lib/validate_params.h"
|
|
#include "mojo/public/cpp/bindings/lib/validation_context.h"
|
|
#include "mojo/public/cpp/bindings/lib/validation_errors.h"
|
|
#include "mojo/public/cpp/bindings/lib/validation_util.h"
|
|
namespace spellcheck {
|
|
namespace mojom {
|
|
|
|
namespace internal {
|
|
|
|
|
|
// static
|
|
bool SpellCheckBDictLanguage_Data::Validate(
|
|
const void* data,
|
|
mojo::internal::ValidationContext* validation_context) {
|
|
if (!data)
|
|
return true;
|
|
|
|
if (!ValidateStructHeaderAndClaimMemory(data, validation_context))
|
|
return false;
|
|
|
|
// NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
|
|
// the message comes from an older version.
|
|
const SpellCheckBDictLanguage_Data* object = static_cast<const SpellCheckBDictLanguage_Data*>(data);
|
|
|
|
static constexpr struct {
|
|
uint32_t version;
|
|
uint32_t num_bytes;
|
|
} kVersionSizes[] = {{ 0, 24 }};
|
|
|
|
if (object->header_.version <=
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].version) {
|
|
// Scan in reverse order to optimize for more recent versions.
|
|
for (int i = arraysize(kVersionSizes) - 1; i >= 0; --i) {
|
|
if (object->header_.version >= kVersionSizes[i].version) {
|
|
if (object->header_.num_bytes == kVersionSizes[i].num_bytes)
|
|
break;
|
|
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
}
|
|
} else if (object->header_.num_bytes <
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].num_bytes) {
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
|
|
if (!mojo::internal::ValidateStruct(object->file, validation_context))
|
|
return false;
|
|
|
|
if (!mojo::internal::ValidatePointerNonNullable(
|
|
object->language, 2, validation_context)) {
|
|
return false;
|
|
}
|
|
const mojo::internal::ContainerValidateParams language_validate_params(
|
|
0, false, nullptr);
|
|
if (!mojo::internal::ValidateContainer(object->language, validation_context,
|
|
&language_validate_params)) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
SpellCheckBDictLanguage_Data::SpellCheckBDictLanguage_Data()
|
|
: header_({sizeof(*this), 0}) {}
|
|
|
|
|
|
// static
|
|
bool SpellCheckResult_Data::Validate(
|
|
const void* data,
|
|
mojo::internal::ValidationContext* validation_context) {
|
|
if (!data)
|
|
return true;
|
|
|
|
if (!ValidateStructHeaderAndClaimMemory(data, validation_context))
|
|
return false;
|
|
|
|
// NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
|
|
// the message comes from an older version.
|
|
const SpellCheckResult_Data* object = static_cast<const SpellCheckResult_Data*>(data);
|
|
|
|
static constexpr struct {
|
|
uint32_t version;
|
|
uint32_t num_bytes;
|
|
} kVersionSizes[] = {{ 0, 32 }};
|
|
|
|
if (object->header_.version <=
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].version) {
|
|
// Scan in reverse order to optimize for more recent versions.
|
|
for (int i = arraysize(kVersionSizes) - 1; i >= 0; --i) {
|
|
if (object->header_.version >= kVersionSizes[i].version) {
|
|
if (object->header_.num_bytes == kVersionSizes[i].num_bytes)
|
|
break;
|
|
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
}
|
|
} else if (object->header_.num_bytes <
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].num_bytes) {
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
|
|
|
|
if (!::spellcheck::mojom::internal::Decoration_Data
|
|
::Validate(object->decoration, validation_context))
|
|
return false;
|
|
|
|
if (!mojo::internal::ValidatePointerNonNullable(
|
|
object->replacements, 4, validation_context)) {
|
|
return false;
|
|
}
|
|
const mojo::internal::ContainerValidateParams replacements_validate_params(
|
|
0, false, nullptr);
|
|
if (!mojo::internal::ValidateContainer(object->replacements, validation_context,
|
|
&replacements_validate_params)) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
SpellCheckResult_Data::SpellCheckResult_Data()
|
|
: header_({sizeof(*this), 0}) {}
|
|
|
|
|
|
// static
|
|
bool SpellChecker_Initialize_Params_Data::Validate(
|
|
const void* data,
|
|
mojo::internal::ValidationContext* validation_context) {
|
|
if (!data)
|
|
return true;
|
|
|
|
if (!ValidateStructHeaderAndClaimMemory(data, validation_context))
|
|
return false;
|
|
|
|
// NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
|
|
// the message comes from an older version.
|
|
const SpellChecker_Initialize_Params_Data* object = static_cast<const SpellChecker_Initialize_Params_Data*>(data);
|
|
|
|
static constexpr struct {
|
|
uint32_t version;
|
|
uint32_t num_bytes;
|
|
} kVersionSizes[] = {{ 0, 32 }};
|
|
|
|
if (object->header_.version <=
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].version) {
|
|
// Scan in reverse order to optimize for more recent versions.
|
|
for (int i = arraysize(kVersionSizes) - 1; i >= 0; --i) {
|
|
if (object->header_.version >= kVersionSizes[i].version) {
|
|
if (object->header_.num_bytes == kVersionSizes[i].num_bytes)
|
|
break;
|
|
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
}
|
|
} else if (object->header_.num_bytes <
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].num_bytes) {
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
|
|
if (!mojo::internal::ValidatePointerNonNullable(
|
|
object->dictionaries, 1, validation_context)) {
|
|
return false;
|
|
}
|
|
const mojo::internal::ContainerValidateParams dictionaries_validate_params(
|
|
0, false, nullptr);
|
|
if (!mojo::internal::ValidateContainer(object->dictionaries, validation_context,
|
|
&dictionaries_validate_params)) {
|
|
return false;
|
|
}
|
|
|
|
if (!mojo::internal::ValidatePointerNonNullable(
|
|
object->custom_words, 2, validation_context)) {
|
|
return false;
|
|
}
|
|
const mojo::internal::ContainerValidateParams custom_words_validate_params(
|
|
0, false, new mojo::internal::ContainerValidateParams(0, false, nullptr));
|
|
if (!mojo::internal::ValidateContainer(object->custom_words, validation_context,
|
|
&custom_words_validate_params)) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
SpellChecker_Initialize_Params_Data::SpellChecker_Initialize_Params_Data()
|
|
: header_({sizeof(*this), 0}) {}
|
|
|
|
|
|
// static
|
|
bool SpellChecker_CustomDictionaryChanged_Params_Data::Validate(
|
|
const void* data,
|
|
mojo::internal::ValidationContext* validation_context) {
|
|
if (!data)
|
|
return true;
|
|
|
|
if (!ValidateStructHeaderAndClaimMemory(data, validation_context))
|
|
return false;
|
|
|
|
// NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
|
|
// the message comes from an older version.
|
|
const SpellChecker_CustomDictionaryChanged_Params_Data* object = static_cast<const SpellChecker_CustomDictionaryChanged_Params_Data*>(data);
|
|
|
|
static constexpr struct {
|
|
uint32_t version;
|
|
uint32_t num_bytes;
|
|
} kVersionSizes[] = {{ 0, 24 }};
|
|
|
|
if (object->header_.version <=
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].version) {
|
|
// Scan in reverse order to optimize for more recent versions.
|
|
for (int i = arraysize(kVersionSizes) - 1; i >= 0; --i) {
|
|
if (object->header_.version >= kVersionSizes[i].version) {
|
|
if (object->header_.num_bytes == kVersionSizes[i].num_bytes)
|
|
break;
|
|
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
}
|
|
} else if (object->header_.num_bytes <
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].num_bytes) {
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
|
|
if (!mojo::internal::ValidatePointerNonNullable(
|
|
object->words_added, 1, validation_context)) {
|
|
return false;
|
|
}
|
|
const mojo::internal::ContainerValidateParams words_added_validate_params(
|
|
0, false, new mojo::internal::ContainerValidateParams(0, false, nullptr));
|
|
if (!mojo::internal::ValidateContainer(object->words_added, validation_context,
|
|
&words_added_validate_params)) {
|
|
return false;
|
|
}
|
|
|
|
if (!mojo::internal::ValidatePointerNonNullable(
|
|
object->words_removed, 2, validation_context)) {
|
|
return false;
|
|
}
|
|
const mojo::internal::ContainerValidateParams words_removed_validate_params(
|
|
0, false, new mojo::internal::ContainerValidateParams(0, false, nullptr));
|
|
if (!mojo::internal::ValidateContainer(object->words_removed, validation_context,
|
|
&words_removed_validate_params)) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
SpellChecker_CustomDictionaryChanged_Params_Data::SpellChecker_CustomDictionaryChanged_Params_Data()
|
|
: header_({sizeof(*this), 0}) {}
|
|
|
|
|
|
// static
|
|
bool SpellCheckHost_RequestDictionary_Params_Data::Validate(
|
|
const void* data,
|
|
mojo::internal::ValidationContext* validation_context) {
|
|
if (!data)
|
|
return true;
|
|
|
|
if (!ValidateStructHeaderAndClaimMemory(data, validation_context))
|
|
return false;
|
|
|
|
// NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
|
|
// the message comes from an older version.
|
|
const SpellCheckHost_RequestDictionary_Params_Data* object = static_cast<const SpellCheckHost_RequestDictionary_Params_Data*>(data);
|
|
|
|
static constexpr struct {
|
|
uint32_t version;
|
|
uint32_t num_bytes;
|
|
} kVersionSizes[] = {{ 0, 8 }};
|
|
|
|
if (object->header_.version <=
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].version) {
|
|
// Scan in reverse order to optimize for more recent versions.
|
|
for (int i = arraysize(kVersionSizes) - 1; i >= 0; --i) {
|
|
if (object->header_.version >= kVersionSizes[i].version) {
|
|
if (object->header_.num_bytes == kVersionSizes[i].num_bytes)
|
|
break;
|
|
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
}
|
|
} else if (object->header_.num_bytes <
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].num_bytes) {
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
SpellCheckHost_RequestDictionary_Params_Data::SpellCheckHost_RequestDictionary_Params_Data()
|
|
: header_({sizeof(*this), 0}) {}
|
|
|
|
|
|
// static
|
|
bool SpellCheckHost_NotifyChecked_Params_Data::Validate(
|
|
const void* data,
|
|
mojo::internal::ValidationContext* validation_context) {
|
|
if (!data)
|
|
return true;
|
|
|
|
if (!ValidateStructHeaderAndClaimMemory(data, validation_context))
|
|
return false;
|
|
|
|
// NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
|
|
// the message comes from an older version.
|
|
const SpellCheckHost_NotifyChecked_Params_Data* object = static_cast<const SpellCheckHost_NotifyChecked_Params_Data*>(data);
|
|
|
|
static constexpr struct {
|
|
uint32_t version;
|
|
uint32_t num_bytes;
|
|
} kVersionSizes[] = {{ 0, 24 }};
|
|
|
|
if (object->header_.version <=
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].version) {
|
|
// Scan in reverse order to optimize for more recent versions.
|
|
for (int i = arraysize(kVersionSizes) - 1; i >= 0; --i) {
|
|
if (object->header_.version >= kVersionSizes[i].version) {
|
|
if (object->header_.num_bytes == kVersionSizes[i].num_bytes)
|
|
break;
|
|
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
}
|
|
} else if (object->header_.num_bytes <
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].num_bytes) {
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
|
|
if (!mojo::internal::ValidatePointerNonNullable(
|
|
object->word, 1, validation_context)) {
|
|
return false;
|
|
}
|
|
if (!mojo::internal::ValidateStruct(object->word, validation_context))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
SpellCheckHost_NotifyChecked_Params_Data::SpellCheckHost_NotifyChecked_Params_Data()
|
|
: header_({sizeof(*this), 0}) {}
|
|
|
|
|
|
// static
|
|
bool SpellCheckHost_CallSpellingService_Params_Data::Validate(
|
|
const void* data,
|
|
mojo::internal::ValidationContext* validation_context) {
|
|
if (!data)
|
|
return true;
|
|
|
|
if (!ValidateStructHeaderAndClaimMemory(data, validation_context))
|
|
return false;
|
|
|
|
// NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
|
|
// the message comes from an older version.
|
|
const SpellCheckHost_CallSpellingService_Params_Data* object = static_cast<const SpellCheckHost_CallSpellingService_Params_Data*>(data);
|
|
|
|
static constexpr struct {
|
|
uint32_t version;
|
|
uint32_t num_bytes;
|
|
} kVersionSizes[] = {{ 0, 16 }};
|
|
|
|
if (object->header_.version <=
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].version) {
|
|
// Scan in reverse order to optimize for more recent versions.
|
|
for (int i = arraysize(kVersionSizes) - 1; i >= 0; --i) {
|
|
if (object->header_.version >= kVersionSizes[i].version) {
|
|
if (object->header_.num_bytes == kVersionSizes[i].num_bytes)
|
|
break;
|
|
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
}
|
|
} else if (object->header_.num_bytes <
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].num_bytes) {
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
|
|
if (!mojo::internal::ValidatePointerNonNullable(
|
|
object->text, 1, validation_context)) {
|
|
return false;
|
|
}
|
|
if (!mojo::internal::ValidateStruct(object->text, validation_context))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
SpellCheckHost_CallSpellingService_Params_Data::SpellCheckHost_CallSpellingService_Params_Data()
|
|
: header_({sizeof(*this), 0}) {}
|
|
|
|
|
|
// static
|
|
bool SpellCheckHost_CallSpellingService_ResponseParams_Data::Validate(
|
|
const void* data,
|
|
mojo::internal::ValidationContext* validation_context) {
|
|
if (!data)
|
|
return true;
|
|
|
|
if (!ValidateStructHeaderAndClaimMemory(data, validation_context))
|
|
return false;
|
|
|
|
// NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
|
|
// the message comes from an older version.
|
|
const SpellCheckHost_CallSpellingService_ResponseParams_Data* object = static_cast<const SpellCheckHost_CallSpellingService_ResponseParams_Data*>(data);
|
|
|
|
static constexpr struct {
|
|
uint32_t version;
|
|
uint32_t num_bytes;
|
|
} kVersionSizes[] = {{ 0, 24 }};
|
|
|
|
if (object->header_.version <=
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].version) {
|
|
// Scan in reverse order to optimize for more recent versions.
|
|
for (int i = arraysize(kVersionSizes) - 1; i >= 0; --i) {
|
|
if (object->header_.version >= kVersionSizes[i].version) {
|
|
if (object->header_.num_bytes == kVersionSizes[i].num_bytes)
|
|
break;
|
|
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
}
|
|
} else if (object->header_.num_bytes <
|
|
kVersionSizes[arraysize(kVersionSizes) - 1].num_bytes) {
|
|
ReportValidationError(
|
|
validation_context,
|
|
mojo::internal::VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER);
|
|
return false;
|
|
}
|
|
|
|
if (!mojo::internal::ValidatePointerNonNullable(
|
|
object->results, 2, validation_context)) {
|
|
return false;
|
|
}
|
|
const mojo::internal::ContainerValidateParams results_validate_params(
|
|
0, false, nullptr);
|
|
if (!mojo::internal::ValidateContainer(object->results, validation_context,
|
|
&results_validate_params)) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
SpellCheckHost_CallSpellingService_ResponseParams_Data::SpellCheckHost_CallSpellingService_ResponseParams_Data()
|
|
: header_({sizeof(*this), 0}) {}
|
|
|
|
} // namespace internal
|
|
} // namespace mojom
|
|
} // namespace spellcheck
|
|
|
|
#if defined(_MSC_VER)
|
|
#pragma warning(pop)
|
|
#endif
|