Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
5ae3eeee
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
5ae3eeee
编写于
11月 17, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
11月 17, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #18212 from taosdata/fix/TD-20456
fix(query): [ASAN] fix time precision conversion overflow
上级
9b29fa0c
0b51e68c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
67 addition
and
25 deletion
+67
-25
source/common/src/ttime.c
source/common/src/ttime.c
+39
-17
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+21
-1
tests/script/tsim/parser/function.sim
tests/script/tsim/parser/function.sim
+7
-7
未找到文件。
source/common/src/ttime.c
浏览文件 @
5ae3eeee
...
...
@@ -436,21 +436,24 @@ int64_t convertTimePrecision(int64_t utime, int32_t fromPrecision, int32_t toPre
ASSERT
(
toPrecision
==
TSDB_TIME_PRECISION_MILLI
||
toPrecision
==
TSDB_TIME_PRECISION_MICRO
||
toPrecision
==
TSDB_TIME_PRECISION_NANO
);
double
tempResult
=
(
double
)
utime
;
switch
(
fromPrecision
)
{
case
TSDB_TIME_PRECISION_MILLI
:
{
switch
(
toPrecision
)
{
case
TSDB_TIME_PRECISION_MILLI
:
return
utime
;
case
TSDB_TIME_PRECISION_MICRO
:
tempResult
*=
1000
;
utime
*=
1000
;
goto
end_
;
if
(
utime
>
INT64_MAX
/
1000
)
{
return
INT64_MAX
;
}
return
utime
*
1000
;
case
TSDB_TIME_PRECISION_NANO
:
tempResult
*=
1000000
;
utime
*=
1000000
;
goto
end_
;
if
(
utime
>
INT64_MAX
/
1000000
)
{
return
INT64_MAX
;
}
return
utime
*
1000000
;
default:
ASSERT
(
0
);
return
utime
;
}
}
// end from milli
case
TSDB_TIME_PRECISION_MICRO
:
{
...
...
@@ -460,9 +463,13 @@ int64_t convertTimePrecision(int64_t utime, int32_t fromPrecision, int32_t toPre
case
TSDB_TIME_PRECISION_MICRO
:
return
utime
;
case
TSDB_TIME_PRECISION_NANO
:
tempResult
*=
1000
;
utime
*=
1000
;
goto
end_
;
if
(
utime
>
INT64_MAX
/
1000
)
{
return
INT64_MAX
;
}
return
utime
*
1000
;
default:
ASSERT
(
0
);
return
utime
;
}
}
// end from micro
case
TSDB_TIME_PRECISION_NANO
:
{
...
...
@@ -473,17 +480,17 @@ int64_t convertTimePrecision(int64_t utime, int32_t fromPrecision, int32_t toPre
return
utime
/
1000
;
case
TSDB_TIME_PRECISION_NANO
:
return
utime
;
default:
ASSERT
(
0
);
return
utime
;
}
}
// end from nano
default:
{
assert
(
0
);
ASSERT
(
0
);
return
utime
;
// only to pass windows compilation
}
}
// end switch fromPrecision
end_:
if
(
tempResult
>=
(
double
)
INT64_MAX
)
return
INT64_MAX
;
if
(
tempResult
<=
(
double
)
INT64_MIN
)
return
INT64_MIN
;
// INT64_MIN means NULL
return
utime
;
}
...
...
@@ -599,18 +606,33 @@ int32_t convertStringToTimestamp(int16_t type, char* inputData, int64_t timePrec
static
int32_t
getDuration
(
int64_t
val
,
char
unit
,
int64_t
*
result
,
int32_t
timePrecision
)
{
switch
(
unit
)
{
case
's'
:
if
(
val
>
INT64_MAX
/
MILLISECOND_PER_SECOND
)
{
return
-
1
;
}
(
*
result
)
=
convertTimePrecision
(
val
*
MILLISECOND_PER_SECOND
,
TSDB_TIME_PRECISION_MILLI
,
timePrecision
);
break
;
case
'm'
:
if
(
val
>
INT64_MAX
/
MILLISECOND_PER_MINUTE
)
{
return
-
1
;
}
(
*
result
)
=
convertTimePrecision
(
val
*
MILLISECOND_PER_MINUTE
,
TSDB_TIME_PRECISION_MILLI
,
timePrecision
);
break
;
case
'h'
:
if
(
val
>
INT64_MAX
/
MILLISECOND_PER_MINUTE
)
{
return
-
1
;
}
(
*
result
)
=
convertTimePrecision
(
val
*
MILLISECOND_PER_HOUR
,
TSDB_TIME_PRECISION_MILLI
,
timePrecision
);
break
;
case
'd'
:
if
(
val
>
INT64_MAX
/
MILLISECOND_PER_DAY
)
{
return
-
1
;
}
(
*
result
)
=
convertTimePrecision
(
val
*
MILLISECOND_PER_DAY
,
TSDB_TIME_PRECISION_MILLI
,
timePrecision
);
break
;
case
'w'
:
if
(
val
>
INT64_MAX
/
MILLISECOND_PER_WEEK
)
{
return
-
1
;
}
(
*
result
)
=
convertTimePrecision
(
val
*
MILLISECOND_PER_WEEK
,
TSDB_TIME_PRECISION_MILLI
,
timePrecision
);
break
;
case
'a'
:
...
...
@@ -650,7 +672,7 @@ int32_t parseAbsoluteDuration(const char* token, int32_t tokenlen, int64_t* dura
/* get the basic numeric value */
int64_t
timestamp
=
taosStr2Int64
(
token
,
&
endPtr
,
10
);
if
(
errno
!=
0
)
{
if
(
timestamp
<
0
||
errno
!=
0
)
{
return
-
1
;
}
...
...
@@ -668,7 +690,7 @@ int32_t parseNatualDuration(const char* token, int32_t tokenLen, int64_t* durati
/* get the basic numeric value */
*
duration
=
taosStr2Int64
(
token
,
NULL
,
10
);
if
(
errno
!=
0
)
{
if
(
*
duration
<
0
||
errno
!=
0
)
{
return
-
1
;
}
...
...
source/libs/function/src/builtins.c
浏览文件 @
5ae3eeee
...
...
@@ -917,6 +917,7 @@ static bool validateHistogramBinDesc(char* binDescStr, int8_t binType, char* err
int32_t
startIndex
;
if
(
numOfParams
!=
4
)
{
snprintf
(
errMsg
,
msgLen
,
"%s"
,
msg1
);
cJSON_Delete
(
binDesc
);
return
false
;
}
...
...
@@ -928,17 +929,20 @@ static bool validateHistogramBinDesc(char* binDescStr, int8_t binType, char* err
if
(
!
cJSON_IsNumber
(
start
)
||
!
cJSON_IsNumber
(
count
)
||
!
cJSON_IsBool
(
infinity
))
{
snprintf
(
errMsg
,
msgLen
,
"%s"
,
msg3
);
cJSON_Delete
(
binDesc
);
return
false
;
}
if
(
count
->
valueint
<=
0
||
count
->
valueint
>
1000
)
{
// limit count to 1000
snprintf
(
errMsg
,
msgLen
,
"%s"
,
msg4
);
cJSON_Delete
(
binDesc
);
return
false
;
}
if
(
isinf
(
start
->
valuedouble
)
||
(
width
!=
NULL
&&
isinf
(
width
->
valuedouble
))
||
(
factor
!=
NULL
&&
isinf
(
factor
->
valuedouble
))
||
(
count
!=
NULL
&&
isinf
(
count
->
valuedouble
)))
{
snprintf
(
errMsg
,
msgLen
,
"%s"
,
msg5
);
cJSON_Delete
(
binDesc
);
return
false
;
}
...
...
@@ -957,6 +961,7 @@ static bool validateHistogramBinDesc(char* binDescStr, int8_t binType, char* err
if
(
width
->
valuedouble
==
0
)
{
snprintf
(
errMsg
,
msgLen
,
"%s"
,
msg6
);
taosMemoryFree
(
intervals
);
cJSON_Delete
(
binDesc
);
return
false
;
}
for
(
int
i
=
0
;
i
<
counter
+
1
;
++
i
)
{
...
...
@@ -964,6 +969,7 @@ static bool validateHistogramBinDesc(char* binDescStr, int8_t binType, char* err
if
(
isinf
(
intervals
[
startIndex
]))
{
snprintf
(
errMsg
,
msgLen
,
"%s"
,
msg5
);
taosMemoryFree
(
intervals
);
cJSON_Delete
(
binDesc
);
return
false
;
}
startIndex
++
;
...
...
@@ -973,11 +979,13 @@ static bool validateHistogramBinDesc(char* binDescStr, int8_t binType, char* err
if
(
start
->
valuedouble
==
0
)
{
snprintf
(
errMsg
,
msgLen
,
"%s"
,
msg7
);
taosMemoryFree
(
intervals
);
cJSON_Delete
(
binDesc
);
return
false
;
}
if
(
factor
->
valuedouble
<
0
||
factor
->
valuedouble
==
0
||
factor
->
valuedouble
==
1
)
{
snprintf
(
errMsg
,
msgLen
,
"%s"
,
msg8
);
taosMemoryFree
(
intervals
);
cJSON_Delete
(
binDesc
);
return
false
;
}
for
(
int
i
=
0
;
i
<
counter
+
1
;
++
i
)
{
...
...
@@ -985,6 +993,7 @@ static bool validateHistogramBinDesc(char* binDescStr, int8_t binType, char* err
if
(
isinf
(
intervals
[
startIndex
]))
{
snprintf
(
errMsg
,
msgLen
,
"%s"
,
msg5
);
taosMemoryFree
(
intervals
);
cJSON_Delete
(
binDesc
);
return
false
;
}
startIndex
++
;
...
...
@@ -992,6 +1001,7 @@ static bool validateHistogramBinDesc(char* binDescStr, int8_t binType, char* err
}
else
{
snprintf
(
errMsg
,
msgLen
,
"%s"
,
msg3
);
taosMemoryFree
(
intervals
);
cJSON_Delete
(
binDesc
);
return
false
;
}
...
...
@@ -1007,6 +1017,7 @@ static bool validateHistogramBinDesc(char* binDescStr, int8_t binType, char* err
}
else
if
(
cJSON_IsArray
(
binDesc
))
{
/* user input bins */
if
(
binType
!=
USER_INPUT_BIN
)
{
snprintf
(
errMsg
,
msgLen
,
"%s"
,
msg3
);
cJSON_Delete
(
binDesc
);
return
false
;
}
numOfBins
=
cJSON_GetArraySize
(
binDesc
);
...
...
@@ -1015,6 +1026,7 @@ static bool validateHistogramBinDesc(char* binDescStr, int8_t binType, char* err
if
(
bin
==
NULL
)
{
snprintf
(
errMsg
,
msgLen
,
"%s"
,
msg3
);
taosMemoryFree
(
intervals
);
cJSON_Delete
(
binDesc
);
return
false
;
}
int
i
=
0
;
...
...
@@ -1023,11 +1035,13 @@ static bool validateHistogramBinDesc(char* binDescStr, int8_t binType, char* err
if
(
!
cJSON_IsNumber
(
bin
))
{
snprintf
(
errMsg
,
msgLen
,
"%s"
,
msg3
);
taosMemoryFree
(
intervals
);
cJSON_Delete
(
binDesc
);
return
false
;
}
if
(
i
!=
0
&&
intervals
[
i
]
<=
intervals
[
i
-
1
])
{
snprintf
(
errMsg
,
msgLen
,
"%s"
,
msg3
);
taosMemoryFree
(
intervals
);
cJSON_Delete
(
binDesc
);
return
false
;
}
bin
=
bin
->
next
;
...
...
@@ -1035,6 +1049,7 @@ static bool validateHistogramBinDesc(char* binDescStr, int8_t binType, char* err
}
}
else
{
snprintf
(
errMsg
,
msgLen
,
"%s"
,
msg3
);
cJSON_Delete
(
binDesc
);
return
false
;
}
...
...
@@ -1464,11 +1479,16 @@ static int32_t translateDerivative(SFunctionNode* pFunc, char* pErrBuf, int32_t
uint8_t
colType
=
((
SExprNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
0
))
->
resType
.
type
;
// param1
SNode
*
pParamNode1
=
nodesListGetNode
(
pFunc
->
pParameterList
,
1
);
SNode
*
pParamNode1
=
nodesListGetNode
(
pFunc
->
pParameterList
,
1
);
SValueNode
*
pValue1
=
(
SValueNode
*
)
pParamNode1
;
if
(
QUERY_NODE_VALUE
!=
nodeType
(
pParamNode1
))
{
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
if
(
pValue1
->
datum
.
i
<=
0
)
{
return
invaildFuncParaValueErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
SValueNode
*
pValue
=
(
SValueNode
*
)
pParamNode1
;
pValue
->
notReserved
=
true
;
...
...
tests/script/tsim/parser/function.sim
浏览文件 @
5ae3eeee
...
...
@@ -821,10 +821,10 @@ sql insert into tm0 values('2015-08-18T00:18:00Z', 2.126) ('2015-08-18T00:24:00Z
sql_error select derivative(ts) from tm0;
sql_error select derivative(k) from tm0;
sql select derivative(k, 0, 0) from tm0;
sql
_error
select derivative(k, 0, 0) from tm0;
sql_error select derivative(k, 1, 911) from tm0;
sql_error select derivative(kx, 1s, 1) from tm0;
sql select derivative(k, -20s, 1) from tm0;
sql
_error
select derivative(k, -20s, 1) from tm0;
sql select derivative(k, 20a, 0) from tm0;
sql select derivative(k, 200a, 0) from tm0;
sql select derivative(k, 999a, 0) from tm0;
...
...
@@ -932,10 +932,10 @@ sql insert into t0 values('2020-1-1 1:4:10', 10);
sql insert into t1 values('2020-1-1 1:1:2', 2);
print ===========================>td-4739
#sql select diff(val) from (select
derivative(k, 1s, 0) val from t1);
#
if $rows != 0 then
#
return -1
#
endi
sql select diff(val) from (select ts,
derivative(k, 1s, 0) val from t1);
if $rows != 0 then
return -1
endi
sql insert into t1 values('2020-1-1 1:1:4', 20);
sql insert into t1 values('2020-1-1 1:1:6', 200);
...
...
@@ -1077,4 +1077,4 @@ endi
if $data11 != NULL then
print ======data11=$data11
return -1
endi
\ No newline at end of file
endi
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录