Add boundary check for SparseTable.

Bug: 13592288
Change-Id: I8bc4ff778c6073d22f86b6050a880b6fb69de31e
This commit is contained in:
Keisuke Kuroyanagi 2014-03-24 14:32:03 +09:00
parent 4c93770430
commit ef665816d0

View file

@ -34,6 +34,12 @@ uint32_t SparseTable::get(const int id) const {
const int indexTableReadingPos = getPosInIndexTable(id); const int indexTableReadingPos = getPosInIndexTable(id);
const int index = mIndexTableBuffer->readUint(INDEX_SIZE, indexTableReadingPos); const int index = mIndexTableBuffer->readUint(INDEX_SIZE, indexTableReadingPos);
const int contentTableReadingPos = getPosInContentTable(id, index); const int contentTableReadingPos = getPosInContentTable(id, index);
if (contentTableReadingPos < 0
|| contentTableReadingPos >= mContentTableBuffer->getTailPosition()) {
AKLOGE("contentTableReadingPos(%d) is invalid. id: %d, index: %d",
contentTableReadingPos, id, index);
return NOT_A_DICT_POS;
}
const int contentValue = mContentTableBuffer->readUint(mDataSize, contentTableReadingPos); const int contentValue = mContentTableBuffer->readUint(mDataSize, contentTableReadingPos);
return contentValue == NOT_EXIST ? NOT_A_DICT_POS : contentValue; return contentValue == NOT_EXIST ? NOT_A_DICT_POS : contentValue;
} }