am 7b496a58: Add boundary check for ver4 bigram/shortcut reading.

* commit '7b496a58612cf1552fe82f8c51a82e7ab82985e1':
  Add boundary check for ver4 bigram/shortcut reading.
main
Keisuke Kuroyanagi 2014-02-25 21:40:54 -08:00 committed by Android Git Automerger
commit 51dde7aa4a
2 changed files with 20 additions and 0 deletions

View File

@ -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;

View File

@ -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) {