diff --git a/source/dnode/vnode/src/tsdb/tsdbDataFileRW.c b/source/dnode/vnode/src/tsdb/tsdbDataFileRW.c index eddbdd0b2f..18ddf74399 100644 --- a/source/dnode/vnode/src/tsdb/tsdbDataFileRW.c +++ b/source/dnode/vnode/src/tsdb/tsdbDataFileRW.c @@ -48,9 +48,24 @@ static int32_t tsdbDataFileReadHeadFooter(SDataFileReader *reader) { if (reader->fd[ftype]) { int32_t encryptAlgorithm = reader->config->tsdb->pVnode->config.tsdbCfg.encryptAlgorithm; char* encryptKey = reader->config->tsdb->pVnode->config.tsdbCfg.encryptKey; +#if 1 code = tsdbReadFile(reader->fd[ftype], reader->config->files[ftype].file.size - sizeof(SHeadFooter), (uint8_t *)reader->headFooter, sizeof(SHeadFooter), 0, encryptAlgorithm, encryptKey); TSDB_CHECK_CODE(code, lino, _exit); +#else + int64_t size = reader->config->files[ftype].file.size; + for (; size > TSDB_FHDR_SIZE; size--) { + code = tsdbReadFile(reader->fd[ftype], size - sizeof(SHeadFooter), (uint8_t *)reader->headFooter, + sizeof(SHeadFooter), 0, encryptAlgorithm, encryptKey); + if (code) continue; + if (reader->headFooter->brinBlkPtr->offset + reader->headFooter->brinBlkPtr->size + sizeof(SHeadFooter) == size) { + break; + } + } + if (size <= TSDB_FHDR_SIZE) { + TSDB_CHECK_CODE(code = TSDB_CODE_FILE_CORRUPTED, lino, _exit); + } +#endif } reader->ctx->headFooterLoaded = true; diff --git a/source/dnode/vnode/src/tsdb/tsdbSttFileRW.c b/source/dnode/vnode/src/tsdb/tsdbSttFileRW.c index 6e56b5677a..478778319d 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSttFileRW.c +++ b/source/dnode/vnode/src/tsdb/tsdbSttFileRW.c @@ -65,9 +65,27 @@ int32_t tsdbSttFileReaderOpen(const char *fname, const SSttFileReaderConfig *con int32_t encryptAlgoirthm = config->tsdb->pVnode->config.tsdbCfg.encryptAlgorithm; char* encryptKey = config->tsdb->pVnode->config.tsdbCfg.encryptKey; +#if 1 code = tsdbReadFile(reader[0]->fd, offset, (uint8_t *)(reader[0]->footer), sizeof(SSttFooter), 0, encryptAlgoirthm, encryptKey); TSDB_CHECK_CODE(code, lino, _exit); +#else + int64_t size = config->file->size; + + for (; size > TSDB_FHDR_SIZE; size--) { + code = tsdbReadFile(reader[0]->fd, size - sizeof(SSttFooter), (uint8_t *)(reader[0]->footer), sizeof(SSttFooter), 0, encryptAlgoirthm, + encryptKey); + if (code) continue; + if ((*reader)->footer->sttBlkPtr->offset + (*reader)->footer->sttBlkPtr->size + sizeof(SSttFooter) == size || + (*reader)->footer->statisBlkPtr->offset + (*reader)->footer->statisBlkPtr->size + sizeof(SSttFooter) == size || + (*reader)->footer->tombBlkPtr->offset + (*reader)->footer->tombBlkPtr->size + sizeof(SSttFooter) == size) { + break; + } + } + if (size <= TSDB_FHDR_SIZE) { + TSDB_CHECK_CODE(code = TSDB_CODE_FILE_CORRUPTED, lino, _exit); + } +#endif _exit: if (code) {