Fix: crash when opening a broken dictionary.

Bug: 13085169
Change-Id: Icfb6184dfefc6a336432203c071d9e30ae8bf990
main
Keisuke Kuroyanagi 2014-02-19 22:11:09 +09:00
parent 97a40d030f
commit 303e767728
3 changed files with 13 additions and 7 deletions

View File

@ -76,7 +76,7 @@ namespace latinime {
}
const Ver4DictBuffers::Ver4DictBuffersPtr dictBuffers =
Ver4DictBuffers::openVer4DictBuffers(dictPath, mmappedBuffer);
if (!dictBuffers.get()->isValid()) {
if (!dictBuffers.get() || !dictBuffers.get()->isValid()) {
AKLOGE("DICT: The dictionary doesn't satisfy ver4 format requirements. path: %s",
path);
ASSERT(false);

View File

@ -28,9 +28,14 @@ namespace latinime {
/* static */ Ver4DictBuffers::Ver4DictBuffersPtr Ver4DictBuffers::openVer4DictBuffers(
const char *const dictPath, const MmappedBuffer::MmappedBufferPtr &headerBuffer) {
const bool isUpdatable = headerBuffer.get() ? headerBuffer.get()->isUpdatable() : false;
if (!headerBuffer.get()) {
ASSERT(false);
AKLOGE("The header buffer must be valid to open ver4 dict buffers.");
return Ver4DictBuffersPtr(0);
}
// TODO: take only dictDirPath, and open both header and trie files in the constructor below
return Ver4DictBuffersPtr(new Ver4DictBuffers(dictPath, headerBuffer, isUpdatable));
return Ver4DictBuffersPtr(new Ver4DictBuffers(
dictPath, headerBuffer, headerBuffer.get()->isUpdatable()));
}
bool Ver4DictBuffers::flushHeaderAndDictBuffers(const char *const dictDirPath,
@ -113,10 +118,11 @@ Ver4DictBuffers::Ver4DictBuffers(const char *const dictPath,
mDictBuffer(MmappedBuffer::openBuffer(dictPath,
Ver4DictConstants::TRIE_FILE_EXTENSION, isUpdatable)),
mHeaderPolicy(headerBuffer.get()->getBuffer(), FormatUtils::VERSION_4),
mExpandableHeaderBuffer(headerBuffer.get()->getBuffer(), mHeaderPolicy.getSize(),
mExpandableHeaderBuffer(headerBuffer.get() ? headerBuffer.get()->getBuffer() : 0,
mHeaderPolicy.getSize(),
BufferWithExtendableBuffer::DEFAULT_MAX_ADDITIONAL_BUFFER_SIZE),
mExpandableTrieBuffer(mDictBuffer.get()->getBuffer(),
mDictBuffer.get()->getBufferSize(),
mExpandableTrieBuffer(mDictBuffer.get() ? mDictBuffer.get()->getBuffer() : 0,
mDictBuffer.get() ? mDictBuffer.get()->getBufferSize() : 0,
BufferWithExtendableBuffer::DEFAULT_MAX_ADDITIONAL_BUFFER_SIZE),
mTerminalPositionLookupTable(dictPath, isUpdatable),
mProbabilityDictContent(dictPath, mHeaderPolicy.hasHistoricalInfoOfWords(),

View File

@ -42,7 +42,7 @@ class Ver4DictBuffers {
}
AK_FORCE_INLINE bool isValid() const {
return mDictBuffer.get() != 0 && mHeaderPolicy.isValid()
return mHeaderBuffer.get() && mDictBuffer.get() && mHeaderPolicy.isValid()
&& mProbabilityDictContent.isValid() && mTerminalPositionLookupTable.isValid()
&& mBigramDictContent.isValid() && mShortcutDictContent.isValid();
}