Merge pull request #27820 from taosdata/fix/TD-32027-3.0

fix(query)[TD-32027]. Fix null pointer access in exceptional cases
This commit is contained in:
Pan Wei 2024-09-13 09:07:08 +08:00 committed by GitHub
commit c35ec8e07c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 22 additions and 12 deletions

View File

@ -4035,26 +4035,30 @@ int32_t doMergeRowsInBuf(SIterInfo* pIter, uint64_t uid, SRowKey* pCurKey, SArra
return code;
}
static int32_t doMergeRowsInFileBlockImpl(SBlockData* pBlockData, int32_t rowIndex, SRowKey* pKey, SRowMerger* pMerger,
static int32_t doMergeRowsInFileBlockImpl(SBlockData* pBlockData, int32_t* rowIndex, SRowKey* pKey, SRowMerger* pMerger,
SVersionRange* pVerRange, int32_t step) {
while (rowIndex < pBlockData->nRow && rowIndex >= 0) {
int32_t code = 0;
while ((*rowIndex) < pBlockData->nRow && (*rowIndex) >= 0) {
SRowKey cur;
tColRowGetKey(pBlockData, rowIndex, &cur);
tColRowGetKey(pBlockData, (*rowIndex), &cur);
if (pkCompEx(&cur, pKey) != 0) {
break;
}
if (pBlockData->aVersion[rowIndex] > pVerRange->maxVer || pBlockData->aVersion[rowIndex] < pVerRange->minVer) {
rowIndex += step;
if (pBlockData->aVersion[(*rowIndex)] > pVerRange->maxVer ||
pBlockData->aVersion[(*rowIndex)] < pVerRange->minVer) {
(*rowIndex) += step;
continue;
}
TSDBROW fRow = tsdbRowFromBlockData(pBlockData, rowIndex);
int32_t code = tsdbRowMergerAdd(pMerger, &fRow, NULL);
rowIndex += step;
TSDBROW fRow = tsdbRowFromBlockData(pBlockData, (*rowIndex));
code = tsdbRowMergerAdd(pMerger, &fRow, NULL);
if (code != TSDB_CODE_SUCCESS) {
return code;
}
return rowIndex;
(*rowIndex) += step;
}
return code;
}
typedef enum {
@ -4076,7 +4080,10 @@ static int32_t checkForNeighborFileBlock(STsdbReader* pReader, STableBlockScanIn
*state = CHECK_FILEBLOCK_QUIT;
if (loadNeighbor && (code == TSDB_CODE_SUCCESS)) {
pDumpInfo->rowIndex = doMergeRowsInFileBlockImpl(pBlockData, pDumpInfo->rowIndex, pKey, pMerger, pVerRange, step);
code = doMergeRowsInFileBlockImpl(pBlockData, &pDumpInfo->rowIndex, pKey, pMerger, pVerRange, step);
if (code != TSDB_CODE_SUCCESS) {
return code;
}
if ((pDumpInfo->rowIndex >= pDumpInfo->totalRows && asc) || (pDumpInfo->rowIndex < 0 && !asc)) {
*state = CHECK_FILEBLOCK_CONT;
}
@ -4096,7 +4103,10 @@ int32_t doMergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pSc
pDumpInfo->rowIndex += step;
if ((pDumpInfo->rowIndex <= pBlockData->nRow - 1 && asc) || (pDumpInfo->rowIndex >= 0 && !asc)) {
pDumpInfo->rowIndex = doMergeRowsInFileBlockImpl(pBlockData, pDumpInfo->rowIndex, pKey, pMerger, pRange, step);
code = doMergeRowsInFileBlockImpl(pBlockData, &pDumpInfo->rowIndex, pKey, pMerger, pRange, step);
if (code != TSDB_CODE_SUCCESS) {
return code;
}
}
// all rows are consumed, let's try next file block