Skip to content

Commit e3bfd65

Browse files
authored
Handle invalid base (#11075)
1 parent 5ac04e4 commit e3bfd65

File tree

7 files changed

+58
-0
lines changed

7 files changed

+58
-0
lines changed

ydb/library/yql/udfs/common/unicode_base/lib/unicode_base_udf.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ namespace {
107107
const int base = static_cast<int>(args[1].GetOrDefault<ui16>(0));
108108
char* pos = nullptr;
109109
unsigned long long res = std::strtoull(input, &pos, base);
110+
if (!res && errno == EINVAL) {
111+
UdfTerminate("Incorrect base");
112+
}
113+
110114
ui64 ret = static_cast<ui64>(res);
111115
if (!res && pos == input) {
112116
UdfTerminate("Input string is not a number");
@@ -125,6 +129,10 @@ namespace {
125129
const int base = static_cast<int>(args[1].GetOrDefault<ui16>(0));
126130
char* pos = nullptr;
127131
unsigned long long res = std::strtoull(input, &pos, base);
132+
if (!res && errno == EINVAL) {
133+
return TUnboxedValuePod();
134+
}
135+
128136
ui64 ret = static_cast<ui64>(res);
129137
if (!res && pos == input) {
130138
return TUnboxedValuePod();

ydb/library/yql/udfs/common/unicode_base/test/canondata/result.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@
4444
"uri": "file://test.test_ToUint64F2_/extracted"
4545
}
4646
],
47+
"test.test[ToUint64F3]": [
48+
{
49+
"uri": "file://test.test_ToUint64F3_/extracted"
50+
}
51+
],
4752
"test.test[ToUint64]": [
4853
{
4954
"uri": "file://test.test_ToUint64_/results.txt"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<tmp_path>/program.sql:<main>: Fatal: Execution
2+
3+
<tmp_path>/program.sql:<main>:2:1: Fatal: Execution of node: Result
4+
SELECT
5+
^
6+
<tmp_path>/program.sql:<main>:2:1: Fatal: Incorrect base
7+
SELECT
8+
^

ydb/library/yql/udfs/common/unicode_base/test/canondata/test.test_TryToUint64_/results.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,35 @@
8686
}
8787
]
8888
};
89+
{
90+
"Write" = [
91+
{
92+
"Type" = [
93+
"ListType";
94+
[
95+
"StructType";
96+
[
97+
[
98+
"column0";
99+
[
100+
"OptionalType";
101+
[
102+
"DataType";
103+
"Uint64"
104+
]
105+
]
106+
]
107+
]
108+
]
109+
];
110+
"Data" = [
111+
[
112+
#
113+
]
114+
]
115+
}
116+
]
117+
};
89118
{
90119
"Write" = [
91120
{
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
xfail
2+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SELECT
2+
Unicode::ToUint64("0",1);
3+

ydb/library/yql/udfs/common/unicode_base/test/cases/TryToUint64.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ SELECT
77
SELECT
88
Unicode::TryToUint64("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 16);
99

10+
SELECT
11+
Unicode::TryToUint64("0", 1);
12+
1013
SELECT
1114
Unicode::TryToUint64("0x1234abcd", 16),
1215
Unicode::TryToUint64("0X4", 16),

0 commit comments

Comments
 (0)