Restore variadic macros in DevToolsEmbedderMessageDispatcher
[chromium-blink-merge.git] / third_party / hunspell / google / bdict.cc
blob3756f358760e59f28d8749395e384b10981b8847
1 // Copyright (c) 2011 The Chromium 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.
5 #include "third_party/hunspell/google/bdict.h"
7 // static
8 bool hunspell::BDict::Verify(const char* bdict_data, size_t bdict_length) {
9 if (bdict_length <= sizeof(hunspell::BDict::Header))
10 return false;
12 const BDict::Header* header =
13 reinterpret_cast<const hunspell::BDict::Header*>(bdict_data);
14 if (header->signature != hunspell::BDict::SIGNATURE ||
15 header->major_version > hunspell::BDict::MAJOR_VERSION ||
16 header->dic_offset > bdict_length)
17 return false;
19 // Get the affix header, make sure there is enough room for it.
20 if (header->aff_offset + sizeof(hunspell::BDict::AffHeader) > bdict_length)
21 return false;
23 // Make sure there is enough room for the affix group count dword.
24 const hunspell::BDict::AffHeader* aff_header =
25 reinterpret_cast<const hunspell::BDict::AffHeader*>(
26 &bdict_data[header->aff_offset]);
27 if (aff_header->affix_group_offset + sizeof(uint32) > bdict_length)
28 return false;
30 // The new BDICT header has a MD5 digest of the dictionary data. Compare the
31 // MD5 digest of the data with the one in the BDICT header.
32 if (header->major_version >= 2) {
33 base::MD5Digest digest;
34 base::MD5Sum(aff_header, bdict_length - header->aff_offset, &digest);
35 if (memcmp(&digest, &header->digest, sizeof(digest)))
36 return false;
39 return true;