Add boundary check for ver2 dict reading.

Bug: 12916055
Change-Id: I78ad1f98a5401f920dcfc3379aa431eb2311ae02
main
Keisuke Kuroyanagi 2014-02-21 13:26:01 +09:00
parent 4cc582f3ba
commit be81b75dec
1 changed files with 15 additions and 0 deletions

View File

@ -87,9 +87,24 @@ int PatriciaTriePolicy::getCodePointsAndProbabilityAndReturnCodePointCount(
int lastCandidatePtNodePos = 0; int lastCandidatePtNodePos = 0;
// Let's loop through PtNodes in this PtNode array searching for either the terminal // Let's loop through PtNodes in this PtNode array searching for either the terminal
// or one of its ascendants. // or one of its ascendants.
if (pos < 0 || pos >= mDictBufferSize) {
AKLOGE("PtNode array position is invalid. pos: %d, dict size: %d",
pos, mDictBufferSize);
mIsCorrupted = true;
ASSERT(false);
*outUnigramProbability = NOT_A_PROBABILITY;
return 0;
}
for (int ptNodeCount = PatriciaTrieReadingUtils::getPtNodeArraySizeAndAdvancePosition( for (int ptNodeCount = PatriciaTrieReadingUtils::getPtNodeArraySizeAndAdvancePosition(
mDictRoot, &pos); ptNodeCount > 0; --ptNodeCount) { mDictRoot, &pos); ptNodeCount > 0; --ptNodeCount) {
const int startPos = pos; const int startPos = pos;
if (pos < 0 || pos >= mDictBufferSize) {
AKLOGE("PtNode position is invalid. pos: %d, dict size: %d", pos, mDictBufferSize);
mIsCorrupted = true;
ASSERT(false);
*outUnigramProbability = NOT_A_PROBABILITY;
return 0;
}
const PatriciaTrieReadingUtils::NodeFlags flags = const PatriciaTrieReadingUtils::NodeFlags flags =
PatriciaTrieReadingUtils::getFlagsAndAdvancePosition(mDictRoot, &pos); PatriciaTrieReadingUtils::getFlagsAndAdvancePosition(mDictRoot, &pos);
const int character = PatriciaTrieReadingUtils::getCodePointAndAdvancePosition( const int character = PatriciaTrieReadingUtils::getCodePointAndAdvancePosition(