diff options
author | 2014-01-24 16:32:42 -0800 | |
---|---|---|
committer | 2014-01-24 16:32:42 -0800 | |
commit | 51c5ec10f9e5ab748e9aeec23ce5fc52c976b0e5 (patch) | |
tree | fd8890b234f0281f6cbfdba5afed2155cfdf5172 /native/jni/src | |
parent | b7197b705bffb82393e38e225f9082205fb26a23 (diff) | |
download | latinime-51c5ec10f9e5ab748e9aeec23ce5fc52c976b0e5.tar.gz latinime-51c5ec10f9e5ab748e9aeec23ce5fc52c976b0e5.tar.xz latinime-51c5ec10f9e5ab748e9aeec23ce5fc52c976b0e5.zip |
Add length check for dict update operations.
Bug: 12602903
Change-Id: I6835dee8bf8b356f0f1cf6c0531bee5b3415a13f
Diffstat (limited to 'native/jni/src')
-rw-r--r-- | native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.cpp b/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.cpp index 448962ec2..b4730fe68 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.cpp +++ b/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.cpp @@ -149,6 +149,15 @@ bool Ver4PatriciaTriePolicy::addUnigramWord(const int *const word, const int len mDictBuffer->getTailPosition()); return false; } + if (length > MAX_WORD_LENGTH) { + AKLOGE("The word is too long to insert to the dictionary, length: %d", length); + return false; + } + if (shortcutLength > MAX_WORD_LENGTH) { + AKLOGE("The shortcutTarget is too long to insert to the dictionary, length: %d", + shortcutLength); + return false; + } DynamicPtReadingHelper readingHelper(mDictBuffer, &mNodeReader); readingHelper.initWithPtNodeArrayPos(getRootPosition()); bool addedNewUnigram = false; @@ -190,6 +199,11 @@ bool Ver4PatriciaTriePolicy::addBigramWords(const int *const word0, const int le mDictBuffer->getTailPosition()); return false; } + if (length0 > MAX_WORD_LENGTH || length1 > MAX_WORD_LENGTH) { + AKLOGE("Either src word or target word is too long to insert the bigram to the dictionary. " + "length0: %d, length1: %d", length0, length1); + return false; + } const int word0Pos = getTerminalPtNodePositionOfWord(word0, length0, false /* forceLowerCaseSearch */); if (word0Pos == NOT_A_DICT_POS) { @@ -223,6 +237,11 @@ bool Ver4PatriciaTriePolicy::removeBigramWords(const int *const word0, const int mDictBuffer->getTailPosition()); return false; } + if (length0 > MAX_WORD_LENGTH || length1 > MAX_WORD_LENGTH) { + AKLOGE("Either src word or target word is too long to remove the bigram to from the " + "dictionary. length0: %d, length1: %d", length0, length1); + return false; + } const int word0Pos = getTerminalPtNodePositionOfWord(word0, length0, false /* forceLowerCaseSearch */); if (word0Pos == NOT_A_DICT_POS) { |