Add boundary check for ver4 bigram/shortcut reading.
Bug: 13185316 Change-Id: I5236222e2a5acda69821062a140c9e36a3024bd2
This commit is contained in:
parent
f818b1aa32
commit
7b496a5861
2 changed files with 20 additions and 0 deletions
|
@ -23,6 +23,13 @@ namespace latinime {
|
|||
const BigramEntry BigramDictContent::getBigramEntryAndAdvancePosition(
|
||||
int *const bigramEntryPos) const {
|
||||
const BufferWithExtendableBuffer *const bigramListBuffer = getContentBuffer();
|
||||
if (*bigramEntryPos < 0 || *bigramEntryPos >= bigramListBuffer->getTailPosition()) {
|
||||
AKLOGE("Invalid bigram entry position. bigramEntryPos: %d, bufSize: %d",
|
||||
*bigramEntryPos, bigramListBuffer->getTailPosition());
|
||||
ASSERT(false);
|
||||
return BigramEntry(false /* hasNext */, NOT_A_PROBABILITY,
|
||||
Ver4DictConstants::NOT_A_TERMINAL_ID);
|
||||
}
|
||||
const int bigramFlags = bigramListBuffer->readUintAndAdvancePosition(
|
||||
Ver4DictConstants::BIGRAM_FLAGS_FIELD_SIZE, bigramEntryPos);
|
||||
const bool hasNext = (bigramFlags & Ver4DictConstants::BIGRAM_HAS_NEXT_MASK) != 0;
|
||||
|
|
|
@ -24,6 +24,19 @@ void ShortcutDictContent::getShortcutEntryAndAdvancePosition(const int maxCodePo
|
|||
int *const outCodePoint, int *const outCodePointCount, int *const outProbability,
|
||||
bool *const outhasNext, int *const shortcutEntryPos) const {
|
||||
const BufferWithExtendableBuffer *const shortcutListBuffer = getContentBuffer();
|
||||
if (*shortcutEntryPos < 0 || *shortcutEntryPos >= shortcutListBuffer->getTailPosition()) {
|
||||
AKLOGE("Invalid shortcut entry position. shortcutEntryPos: %d, bufSize: %d",
|
||||
*shortcutEntryPos, shortcutListBuffer->getTailPosition());
|
||||
ASSERT(false);
|
||||
if (outhasNext) {
|
||||
*outhasNext = false;
|
||||
}
|
||||
if (outCodePointCount) {
|
||||
*outCodePointCount = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const int shortcutFlags = shortcutListBuffer->readUintAndAdvancePosition(
|
||||
Ver4DictConstants::SHORTCUT_FLAGS_FIELD_SIZE, shortcutEntryPos);
|
||||
if (outProbability) {
|
||||
|
|
Loading…
Reference in a new issue