fix: window fill ts range check with int64 overflow
This commit is contained in:
parent
0a74db1ef4
commit
6713882b48
|
@ -118,6 +118,12 @@ int32_t getDnodeListFromCache(SParseMetaCache* pMetaCache, SArray** pDnodes);
|
||||||
void destoryParseMetaCache(SParseMetaCache* pMetaCache, bool request);
|
void destoryParseMetaCache(SParseMetaCache* pMetaCache, bool request);
|
||||||
SNode* createSelectStmtImpl(bool isDistinct, SNodeList* pProjectionList, SNode* pTable);
|
SNode* createSelectStmtImpl(bool isDistinct, SNodeList* pProjectionList, SNode* pTable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief return a - b with overflow check
|
||||||
|
* @retval val range between [INT64_MIN, INT64_MAX]
|
||||||
|
*/
|
||||||
|
int64_t int64SafeSub(int64_t a, int64_t b);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -3296,23 +3296,25 @@ static int32_t checkFill(STranslateContext* pCxt, SFillNode* pFill, SValueNode*
|
||||||
if (NULL == pInterval) {
|
if (NULL == pInterval) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
int64_t timeRange = 0;
|
||||||
int64_t timeRange = TABS(pFill->timeRange.skey - pFill->timeRange.ekey);
|
|
||||||
int64_t intervalRange = 0;
|
int64_t intervalRange = 0;
|
||||||
if (IS_CALENDAR_TIME_DURATION(pInterval->unit)) {
|
if (!pCxt->createStream) {
|
||||||
int64_t f = 1;
|
int64_t res = int64SafeSub(pFill->timeRange.skey, pFill->timeRange.ekey);
|
||||||
if (pInterval->unit == 'n') {
|
timeRange = res < 0 ? res == INT64_MIN ? INT64_MAX : -res : res;
|
||||||
f = 30LL * MILLISECOND_PER_DAY;
|
if (IS_CALENDAR_TIME_DURATION(pInterval->unit)) {
|
||||||
} else if (pInterval->unit == 'y') {
|
int64_t f = 1;
|
||||||
f = 365LL * MILLISECOND_PER_DAY;
|
if (pInterval->unit == 'n') {
|
||||||
|
f = 30LL * MILLISECOND_PER_DAY;
|
||||||
|
} else if (pInterval->unit == 'y') {
|
||||||
|
f = 365LL * MILLISECOND_PER_DAY;
|
||||||
|
}
|
||||||
|
intervalRange = pInterval->datum.i * f;
|
||||||
|
} else {
|
||||||
|
intervalRange = pInterval->datum.i;
|
||||||
|
}
|
||||||
|
if ((timeRange / intervalRange) >= MAX_INTERVAL_TIME_WINDOW) {
|
||||||
|
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_FILL_TIME_RANGE);
|
||||||
}
|
}
|
||||||
intervalRange = pInterval->datum.i * f;
|
|
||||||
} else {
|
|
||||||
intervalRange = pInterval->datum.i;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((timeRange / intervalRange) >= MAX_INTERVAL_TIME_WINDOW) {
|
|
||||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_FILL_TIME_RANGE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
|
|
@ -1140,3 +1140,18 @@ void destoryParseMetaCache(SParseMetaCache* pMetaCache, bool request) {
|
||||||
taosHashCleanup(pMetaCache->pTableIndex);
|
taosHashCleanup(pMetaCache->pTableIndex);
|
||||||
taosHashCleanup(pMetaCache->pTableCfg);
|
taosHashCleanup(pMetaCache->pTableCfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t int64SafeSub(int64_t a, int64_t b) {
|
||||||
|
int64_t res = (uint64_t)a - (uint64_t)b;
|
||||||
|
|
||||||
|
if (a >= 0 && b < 0) {
|
||||||
|
if ((uint64_t)res > (uint64_t)INT64_MAX) {
|
||||||
|
// overflow
|
||||||
|
res = INT64_MAX;
|
||||||
|
}
|
||||||
|
} else if (a < 0 && b > 0 && res >= 0) {
|
||||||
|
// underflow
|
||||||
|
res = INT64_MIN;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue