From 2490995d6ca79b359f2e39808bbfc8dbab0628d5 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 16 Oct 2020 09:52:49 +0000 Subject: [PATCH 1/4] TD-1530 fix invalid read/write while execute tags_filter.sim --- src/inc/taosdef.h | 4 ++-- src/tsdb/src/tsdbRead.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/inc/taosdef.h b/src/inc/taosdef.h index 01a4ed32f1..aee60da201 100644 --- a/src/inc/taosdef.h +++ b/src/inc/taosdef.h @@ -194,9 +194,9 @@ static FORCE_INLINE bool isNull(const char *val, int32_t type) { case TSDB_DATA_TYPE_DOUBLE: return *(uint64_t *)val == TSDB_DATA_DOUBLE_NULL; case TSDB_DATA_TYPE_NCHAR: - return *(uint32_t*) varDataVal(val) == TSDB_DATA_NCHAR_NULL; + return varDataLen(val) == sizeof(int32_t) && *(uint32_t*) varDataVal(val) == TSDB_DATA_NCHAR_NULL; case TSDB_DATA_TYPE_BINARY: - return *(uint8_t *) varDataVal(val) == TSDB_DATA_BINARY_NULL; + return varDataLen(val) == sizeof(int8_t) && *(uint8_t *) varDataVal(val) == TSDB_DATA_BINARY_NULL; default: return false; }; diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index f0a2694b60..8ca71e4555 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -2284,7 +2284,7 @@ void filterPrepare(void* expr, void* param) { if (pInfo->optr == TSDB_RELATION_IN) { pInfo->q = (char*) pCond->arr; } else { - pInfo->q = calloc(1, pSchema->bytes); + pInfo->q = calloc(1, pSchema->bytes + TSDB_NCHAR_SIZE); // to make sure tonchar does not cause invalid write, since the '\0' needs at least sizeof(wchar_t) space. tVariantDump(pCond, pInfo->q, pSchema->type, true); } } From 1ad7827fc19132b276d02e5bdc16ce990420d9a8 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 16 Oct 2020 18:47:02 +0800 Subject: [PATCH 2/4] TD-1530 --- .../general/insert/query_block1_memory.sim | 25 +++++++++++-------- tests/script/general/parser/where.sim | 10 +++++--- tests/script/general/stream/table_n.sim | 2 ++ tests/script/unique/cluster/vgroup100.sim | 9 ++++--- 4 files changed, 29 insertions(+), 17 deletions(-) diff --git a/tests/script/general/insert/query_block1_memory.sim b/tests/script/general/insert/query_block1_memory.sim index 83509ad5b0..b4b3ca384b 100644 --- a/tests/script/general/insert/query_block1_memory.sim +++ b/tests/script/general/insert/query_block1_memory.sim @@ -30,9 +30,12 @@ print =============== step 1 $x = $N $y = $N / 2 while $x > $y + $y = $x * 60000 + $ms = 1601481600000 - $y + $ms = $x . m $xt = - . $x - sql insert into $tb values (now - $ms , -$x ) + sql insert into $tb values ($ms , -$x ) $x = $x - 1 endw @@ -45,8 +48,10 @@ endi $x = $N / 2 $y = $N while $x < $y - $ms = $x . m - sql insert into $tb values (now + $ms , $x ) + $y = $x * 60000 + $ms = 1601481600000 + $y + + sql insert into $tb values ($ms , $x ) $x = $x + 1 endw sql select * from $tb @@ -60,14 +65,14 @@ print =============== step 2 $N1 = $N + 1 $result1 = $N / 2 $result2 = $N -$step = $N1 . m +$step = $N1 * 60000 -$start1 = now- . $step -$start2 = now -$start3 = now+ . $step -$end1 = now- . $step -$end2 = now -$end3 = now+ . $step +$start1 = 1601481600000 - $step +$start2 = 1601481600000 +$start3 = 1601481600000 + $step +$end1 = 1601481600000 - $step +$end2 = 1601481600000 +$end3 = 1601481600000 + $step sql select * from $tb where ts < $start1 and ts > $end1 if $rows != 0 then diff --git a/tests/script/general/parser/where.sim b/tests/script/general/parser/where.sim index e609dda652..5cac3f4723 100644 --- a/tests/script/general/parser/where.sim +++ b/tests/script/general/parser/where.sim @@ -33,7 +33,8 @@ while $i < $tbNum $x = 0 while $x < $rowNum - $ms = $x . m + $y = $x * 60000 + $ms = 1600099200000 + $y $c = $x / 100 $c = $c * 100 $c = $x - $c @@ -41,7 +42,7 @@ while $i < $tbNum $binary = $binary . ' $nchar = 'nchar . $c $nchar = $nchar . ' - sql insert into $tb values (now + $ms , $c , $c , $c , $c , $c , $c , $c , $binary , $nchar ) + sql insert into $tb values ($ms , $c , $c , $c , $c , $c , $c , $c , $binary , $nchar ) $x = $x + 1 endw @@ -299,7 +300,8 @@ while $i < 1 $x = 0 while $x < 10000 - $ms = $x . m + $y = $x * 60000 + $ms = 1601481600000 + $y $c = $x / 100 $c = $c * 100 $c = $x - $c @@ -307,7 +309,7 @@ while $i < 1 $binary = $binary . ' $nchar = 'nchar . $c $nchar = $nchar . ' - sql insert into $tb values (now + $ms , null , null , null , null , null , null , null , null , null ) + sql insert into $tb values ($ms , null , null , null , null , null , null , null , null , null ) $x = $x + 1 endw diff --git a/tests/script/general/stream/table_n.sim b/tests/script/general/stream/table_n.sim index d1b4a87a9e..a336772a98 100644 --- a/tests/script/general/stream/table_n.sim +++ b/tests/script/general/stream/table_n.sim @@ -289,3 +289,5 @@ endi if $data09 != 20 then return -1 endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/script/unique/cluster/vgroup100.sim b/tests/script/unique/cluster/vgroup100.sim index 7879c5529e..68a5bad6b3 100644 --- a/tests/script/unique/cluster/vgroup100.sim +++ b/tests/script/unique/cluster/vgroup100.sim @@ -29,6 +29,9 @@ system sh/exec.sh -n dnode3 -s start sleep 3000 +$maxNum = 102 +$maxNum = 12 + $x = 0 show2: $x = $x + 1 @@ -58,7 +61,7 @@ endi print ============================== step3 $count = 2 -while $count < 102 +while $count < $maxNum $db = d . $count $tb = $db . .t $tb2 = $db . .t2 @@ -73,7 +76,7 @@ endw print ============================== step4 $count = 2 -while $count < 102 +while $count < $maxNum $db = d . $count $tb = $db . .t sql select * from $tb @@ -131,7 +134,7 @@ show8: endi $count = 2 -while $count < 102 +while $count < $maxNum $db = d . $count $tb = $db . .t sql select * from $tb From 51c09bb1edcb98c08acdb70cf6bbbec8e69619b8 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 16 Oct 2020 18:56:15 +0800 Subject: [PATCH 3/4] TD-1530 aligin double in arm32 --- src/client/src/tscFunctionImpl.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/client/src/tscFunctionImpl.c b/src/client/src/tscFunctionImpl.c index 60e9596ec4..1b4f92d3fc 100644 --- a/src/client/src/tscFunctionImpl.c +++ b/src/client/src/tscFunctionImpl.c @@ -2445,8 +2445,8 @@ static bool percentile_function_setup(SQLFunctionCtx *pCtx) { // in the first round, get the min-max value of all involved data SResultInfo *pResInfo = GET_RES_INFO(pCtx); SPercentileInfo *pInfo = pResInfo->interResultBuf; - pInfo->minval = DBL_MAX; - pInfo->maxval = -DBL_MAX; + SET_DOUBLE_VAL(&pInfo->minval, DBL_MAX); + SET_DOUBLE_VAL(&pInfo->maxval, -DBL_MAX); pInfo->numOfElems = 0; return true; @@ -2461,12 +2461,12 @@ static void percentile_function(SQLFunctionCtx *pCtx) { // the first stage, only acquire the min/max value if (pInfo->stage == 0) { if (pCtx->preAggVals.isSet) { - if (pInfo->minval > pCtx->preAggVals.statis.min) { - pInfo->minval = (double)pCtx->preAggVals.statis.min; + if (GET_DOUBLE_VAL(&pInfo->minval) > pCtx->preAggVals.statis.min) { + SET_DOUBLE_VAL(&pInfo->minval, (double)pCtx->preAggVals.statis.min); } - if (pInfo->maxval < pCtx->preAggVals.statis.max) { - pInfo->maxval = (double)pCtx->preAggVals.statis.max; + if (GET_DOUBLE_VAL(&pInfo->maxval) < pCtx->preAggVals.statis.max) { + SET_DOUBLE_VAL(&pInfo->maxval, (double)pCtx->preAggVals.statis.max); } pInfo->numOfElems += (pCtx->size - pCtx->preAggVals.statis.numOfNull); @@ -2500,12 +2500,12 @@ static void percentile_function(SQLFunctionCtx *pCtx) { break; } - if (v < pInfo->minval) { - pInfo->minval = v; + if (v < GET_DOUBLE_VAL(&pInfo->minval)) { + SET_DOUBLE_VAL(&pInfo->minval, v); } - if (v > pInfo->maxval) { - pInfo->maxval = v; + if (v > GET_DOUBLE_VAL(&pInfo->maxval)) { + SET_DOUBLE_VAL(&pInfo->maxval, v); } pInfo->numOfElems += 1; @@ -2564,12 +2564,12 @@ static void percentile_function_f(SQLFunctionCtx *pCtx, int32_t index) { break; } - if (v < pInfo->minval) { - pInfo->minval = v; + if (v < GET_DOUBLE_VAL(&pInfo->minval)) { + SET_DOUBLE_VAL(&pInfo->minval, v); } - if (v > pInfo->maxval) { - pInfo->maxval = v; + if (v > GET_DOUBLE_VAL(&pInfo->maxval)) { + SET_DOUBLE_VAL(&pInfo->maxval, v); } pInfo->numOfElems += 1; @@ -2609,7 +2609,7 @@ static void percentile_next_step(SQLFunctionCtx *pCtx) { } pInfo->stage += 1; - pInfo->pMemBucket = tMemBucketCreate(pCtx->inputBytes, pCtx->inputType, pInfo->minval, pInfo->maxval); + pInfo->pMemBucket = tMemBucketCreate(pCtx->inputBytes, pCtx->inputType, GET_DOUBLE_VAL(&pInfo->minval), GET_DOUBLE_VAL(&pInfo->maxval)); } else { pResInfo->complete = true; } From 9c9593d58c277c463f62cfbeebda1295207dde90 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 16 Oct 2020 13:59:00 +0000 Subject: [PATCH 4/4] scripts --- tests/script/general/insert/query_block1_memory.sim | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/script/general/insert/query_block1_memory.sim b/tests/script/general/insert/query_block1_memory.sim index b4b3ca384b..bec9190f9b 100644 --- a/tests/script/general/insert/query_block1_memory.sim +++ b/tests/script/general/insert/query_block1_memory.sim @@ -30,10 +30,9 @@ print =============== step 1 $x = $N $y = $N / 2 while $x > $y - $y = $x * 60000 - $ms = 1601481600000 - $y + $z = $x * 60000 + $ms = 1601481600000 - $z - $ms = $x . m $xt = - . $x sql insert into $tb values ($ms , -$x ) $x = $x - 1 @@ -48,8 +47,8 @@ endi $x = $N / 2 $y = $N while $x < $y - $y = $x * 60000 - $ms = 1601481600000 + $y + $z = $x * 60000 + $ms = 1601481600000 + $z sql insert into $tb values ($ms , $x ) $x = $x + 1