Add boundary check for ver2 dict reading.
Bug: 12916055 Change-Id: I78ad1f98a5401f920dcfc3379aa431eb2311ae02main
parent
4cc582f3ba
commit
be81b75dec
|
@ -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(
|
||||||
|
|
Loading…
Reference in New Issue