am 009dcac3: Boundary check for children creating of PatriciaTriePolicy.
* commit '009dcac33f53bb92d0a8b7f0789a26568b04f014': Boundary check for children creating of PatriciaTriePolicy.main
commit
2f11bc9bae
|
@ -31,9 +31,21 @@ void PatriciaTriePolicy::createAndGetAllChildNodes(const DicNode *const dicNode,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int nextPos = dicNode->getChildrenPos();
|
int nextPos = dicNode->getChildrenPos();
|
||||||
|
if (nextPos < 0 || nextPos >= mDictBufferSize) {
|
||||||
|
AKLOGE("Children PtNode array position is invalid. pos: %d, dict size: %d",
|
||||||
|
nextPos, mDictBufferSize);
|
||||||
|
ASSERT(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
const int childCount = PatriciaTrieReadingUtils::getPtNodeArraySizeAndAdvancePosition(
|
const int childCount = PatriciaTrieReadingUtils::getPtNodeArraySizeAndAdvancePosition(
|
||||||
mDictRoot, &nextPos);
|
mDictRoot, &nextPos);
|
||||||
for (int i = 0; i < childCount; i++) {
|
for (int i = 0; i < childCount; i++) {
|
||||||
|
if (nextPos < 0 || nextPos >= mDictBufferSize) {
|
||||||
|
AKLOGE("Child PtNode position is invalid. pos: %d, dict size: %d, childCount: %d / %d",
|
||||||
|
nextPos, mDictBufferSize, i, childCount);
|
||||||
|
ASSERT(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
nextPos = createAndGetLeavingChildNode(dicNode, nextPos, childDicNodes);
|
nextPos = createAndGetLeavingChildNode(dicNode, nextPos, childDicNodes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ class PatriciaTriePolicy : public DictionaryStructureWithBufferPolicy {
|
||||||
PatriciaTriePolicy(const MmappedBuffer *const buffer)
|
PatriciaTriePolicy(const MmappedBuffer *const buffer)
|
||||||
: mBuffer(buffer), mHeaderPolicy(mBuffer->getBuffer(), buffer->getBufferSize()),
|
: mBuffer(buffer), mHeaderPolicy(mBuffer->getBuffer(), buffer->getBufferSize()),
|
||||||
mDictRoot(mBuffer->getBuffer() + mHeaderPolicy.getSize()),
|
mDictRoot(mBuffer->getBuffer() + mHeaderPolicy.getSize()),
|
||||||
|
mDictBufferSize(mBuffer->getBufferSize() - mHeaderPolicy.getSize()),
|
||||||
mBigramListPolicy(mDictRoot), mShortcutListPolicy(mDictRoot) {}
|
mBigramListPolicy(mDictRoot), mShortcutListPolicy(mDictRoot) {}
|
||||||
|
|
||||||
~PatriciaTriePolicy() {
|
~PatriciaTriePolicy() {
|
||||||
|
@ -118,6 +119,7 @@ class PatriciaTriePolicy : public DictionaryStructureWithBufferPolicy {
|
||||||
const MmappedBuffer *const mBuffer;
|
const MmappedBuffer *const mBuffer;
|
||||||
const HeaderPolicy mHeaderPolicy;
|
const HeaderPolicy mHeaderPolicy;
|
||||||
const uint8_t *const mDictRoot;
|
const uint8_t *const mDictRoot;
|
||||||
|
const int mDictBufferSize;
|
||||||
const BigramListPolicy mBigramListPolicy;
|
const BigramListPolicy mBigramListPolicy;
|
||||||
const ShortcutListPolicy mShortcutListPolicy;
|
const ShortcutListPolicy mShortcutListPolicy;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue