OLD | NEW |
1 // Copyright 2008 Google Inc. All Rights Reserved. | 1 // Copyright 2008 Google Inc. All Rights Reserved. |
2 | 2 |
3 #include "third_party/hunspell/google/bdict_reader.h" | 3 #include "third_party/hunspell/google/bdict_reader.h" |
4 | 4 |
5 #include "base/logging.h" | 5 #include "base/logging.h" |
6 | 6 |
7 namespace hunspell { | 7 namespace hunspell { |
8 | 8 |
9 // Like the "Visitor" design pattern, this lightweight object provides an | 9 // Like the "Visitor" design pattern, this lightweight object provides an |
10 // interface around a serialized trie node at the given address in the memory. | 10 // interface around a serialized trie node at the given address in the memory. |
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 header_(NULL) { | 642 header_(NULL) { |
643 } | 643 } |
644 | 644 |
645 bool BDictReader::Init(const unsigned char* bdict_data, size_t bdict_length) { | 645 bool BDictReader::Init(const unsigned char* bdict_data, size_t bdict_length) { |
646 if (bdict_length < sizeof(BDict::Header)) | 646 if (bdict_length < sizeof(BDict::Header)) |
647 return false; | 647 return false; |
648 | 648 |
649 // Check header. | 649 // Check header. |
650 header_ = reinterpret_cast<const BDict::Header*>(bdict_data); | 650 header_ = reinterpret_cast<const BDict::Header*>(bdict_data); |
651 if (header_->signature != BDict::SIGNATURE || | 651 if (header_->signature != BDict::SIGNATURE || |
652 header_->major_version != 1 || | 652 header_->major_version > BDict::MAJOR_VERSION || |
653 header_->aff_offset > bdict_length || | |
654 header_->dic_offset > bdict_length) | 653 header_->dic_offset > bdict_length) |
655 return false; | 654 return false; |
656 | 655 |
657 // Get the affix header, make sure there is enough room for it. | 656 // Get the affix header, make sure there is enough room for it. |
658 if (header_->aff_offset + sizeof(BDict::AffHeader) > bdict_length) | 657 if (header_->aff_offset + sizeof(BDict::AffHeader) > bdict_length) |
659 return false; | 658 return false; |
660 aff_header_ = reinterpret_cast<const BDict::AffHeader*>( | 659 aff_header_ = reinterpret_cast<const BDict::AffHeader*>( |
661 &bdict_data[header_->aff_offset]); | 660 &bdict_data[header_->aff_offset]); |
662 | 661 |
663 // Make sure there is enough room for the affix group count dword. | 662 // Make sure there is enough room for the affix group count dword. |
664 if (aff_header_->affix_group_offset + sizeof(uint32) > bdict_length) | 663 if (aff_header_->affix_group_offset + sizeof(uint32) > bdict_length) |
665 return false; | 664 return false; |
666 | 665 |
| 666 // This function is called from SpellCheck::SpellCheckWord(), which blocks |
| 667 // WebKit. To avoid blocking WebKit for a long time, we do not check the MD5 |
| 668 // digest here. Instead we check the MD5 digest when Chrome finishes |
| 669 // downloading a dictionary. |
| 670 |
667 // Don't set these until the end. This way, NULL bdict_data_ will indicate | 671 // Don't set these until the end. This way, NULL bdict_data_ will indicate |
668 // failure. | 672 // failure. |
669 bdict_data_ = bdict_data; | 673 bdict_data_ = bdict_data; |
670 bdict_length_ = bdict_length; | 674 bdict_length_ = bdict_length; |
671 return true; | 675 return true; |
672 } | 676 } |
673 | 677 |
674 int BDictReader::FindWord( | 678 int BDictReader::FindWord( |
675 const char* word, | 679 const char* word, |
676 int affix_indices[BDict::MAX_AFFIXES_PER_WORD]) const { | 680 int affix_indices[BDict::MAX_AFFIXES_PER_WORD]) const { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 aff_header_->rep_offset); | 722 aff_header_->rep_offset); |
719 } | 723 } |
720 | 724 |
721 | 725 |
722 WordIterator BDictReader::GetAllWordIterator() const { | 726 WordIterator BDictReader::GetAllWordIterator() const { |
723 NodeReader reader(bdict_data_, bdict_length_, header_->dic_offset, 0); | 727 NodeReader reader(bdict_data_, bdict_length_, header_->dic_offset, 0); |
724 return WordIterator(reader); | 728 return WordIterator(reader); |
725 } | 729 } |
726 | 730 |
727 } // namespace hunspell | 731 } // namespace hunspell |
OLD | NEW |