From f5758a29daf38ed65e912d65a509795e2d493319 Mon Sep 17 00:00:00 2001 From: lichuang Date: Tue, 27 Jul 2021 10:40:42 +0800 Subject: [PATCH] [TD-5504]fix tsdbRestoreLastColumns run time bug:memory heap overflow --- src/tsdb/src/tsdbMain.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/tsdb/src/tsdbMain.c b/src/tsdb/src/tsdbMain.c index f995295745..40af6348b7 100644 --- a/src/tsdb/src/tsdbMain.c +++ b/src/tsdb/src/tsdbMain.c @@ -735,11 +735,12 @@ static int tsdbRestoreLastColumns(STsdbRepo *pRepo, STable *pTable, SReadH* pRea continue; } // save not-null column + uint16_t bytes = IS_VAR_DATA_TYPE(pCol->type) ? varDataTLen(tdGetColDataOfRow(pDataCol, rowId)) : TYPE_BYTES[pCol->type]; SDataCol *pLastCol = &(pTable->lastCols[idx]); - pLastCol->pData = malloc(pCol->bytes); - pLastCol->bytes = pCol->bytes; + pLastCol->pData = malloc(bytes); + pLastCol->bytes = bytes; pLastCol->colId = pCol->colId; - memcpy(pLastCol->pData, value, pCol->bytes); + memcpy(pLastCol->pData, value, bytes); // save row ts(in column 0) pDataCol = pReadh->pDCols[0]->cols + 0; -- GitLab