aboutsummaryrefslogtreecommitdiffstats
path: root/native/jni/src
diff options
context:
space:
mode:
authorKeisuke Kuroyanagi <ksk@google.com>2014-01-24 16:32:42 -0800
committerKeisuke Kuroyanagi <ksk@google.com>2014-01-24 16:32:42 -0800
commit51c5ec10f9e5ab748e9aeec23ce5fc52c976b0e5 (patch)
treefd8890b234f0281f6cbfdba5afed2155cfdf5172 /native/jni/src
parentb7197b705bffb82393e38e225f9082205fb26a23 (diff)
downloadlatinime-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.cpp19
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) {