Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 303e7677 authored by Keisuke Kuroyanagi's avatar Keisuke Kuroyanagi
Browse files

Fix: crash when opening a broken dictionary.

Bug: 13085169
Change-Id: Icfb6184dfefc6a336432203c071d9e30ae8bf990
parent 97a40d03
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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);
+11 −5
Original line number Diff line number Diff line
@@ -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(),
+1 −1
Original line number Diff line number Diff line
@@ -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();
    }