From dff0b3c4bb06e71cf74ba7bcbc036ea3cddd1210 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 23 Nov 2022 22:43:11 +0800 Subject: [PATCH] fix: [ASAN] heap buffer overflow in sclfunc.c --- source/libs/scalar/src/sclfunc.c | 41 ++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index 5496c5d1ab..d261d572f0 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -1758,18 +1758,45 @@ int32_t sumScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam * break; } - if (IS_SIGNED_NUMERIC_TYPE(type)) { - int64_t *in = (int64_t *)pInputData->pData; + if (IS_SIGNED_NUMERIC_TYPE(type) || type == TSDB_DATA_TYPE_BOOL) { int64_t *out = (int64_t *)pOutputData->pData; - *out += in[i]; + if (type == TSDB_DATA_TYPE_TINYINT || type == TSDB_DATA_TYPE_BOOL) { + int8_t *in = (int8_t *)pInputData->pData; + *out += in[i]; + } else if (type == TSDB_DATA_TYPE_SMALLINT) { + int16_t *in = (int16_t *)pInputData->pData; + *out += in[i]; + } else if (type == TSDB_DATA_TYPE_INT) { + int32_t *in = (int32_t *)pInputData->pData; + *out += in[i]; + } else if (type == TSDB_DATA_TYPE_BIGINT) { + int64_t *in = (int64_t *)pInputData->pData; + *out += in[i]; + } } else if (IS_UNSIGNED_NUMERIC_TYPE(type)) { - uint64_t *in = (uint64_t *)pInputData->pData; uint64_t *out = (uint64_t *)pOutputData->pData; - *out += in[i]; + if (type == TSDB_DATA_TYPE_UTINYINT) { + uint8_t *in = (uint8_t *)pInputData->pData; + *out += in[i]; + } else if (type == TSDB_DATA_TYPE_USMALLINT) { + uint16_t *in = (uint16_t *)pInputData->pData; + *out += in[i]; + } else if (type == TSDB_DATA_TYPE_UINT) { + uint32_t *in = (uint32_t *)pInputData->pData; + *out += in[i]; + } else if (type == TSDB_DATA_TYPE_UBIGINT) { + uint64_t *in = (uint64_t *)pInputData->pData; + *out += in[i]; + } } else if (IS_FLOAT_TYPE(type)) { - double *in = (double *)pInputData->pData; double *out = (double *)pOutputData->pData; - *out += in[i]; + if (type == TSDB_DATA_TYPE_FLOAT) { + float *in = (float *)pInputData->pData; + *out += in[i]; + } else if (type == TSDB_DATA_TYPE_DOUBLE) { + double *in = (double *)pInputData->pData; + *out += in[i]; + } } } -- GitLab