Fix overflow in mapPopulateSeries

This commit is contained in:
Alexey Milovidov 2021-02-06 23:18:42 +03:00
parent b0f201df72
commit 1209c02869
3 changed files with 11 additions and 1 deletions

View File

@ -16,6 +16,7 @@ namespace ErrorCodes
extern const int ILLEGAL_COLUMN; extern const int ILLEGAL_COLUMN;
extern const int ILLEGAL_TYPE_OF_ARGUMENT; extern const int ILLEGAL_TYPE_OF_ARGUMENT;
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH; extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
extern const int TOO_LARGE_ARRAY_SIZE;
} }
class FunctionMapPopulateSeries : public IFunction class FunctionMapPopulateSeries : public IFunction
@ -188,9 +189,13 @@ private:
} }
} }
static constexpr size_t MAX_ARRAY_SIZE = 1ULL << 30;
if (static_cast<size_t>(max_key - min_key) > MAX_ARRAY_SIZE)
throw Exception(ErrorCodes::TOO_LARGE_ARRAY_SIZE, "Too large array size in the result of function {}", getName());
/* fill the result arrays */ /* fill the result arrays */
KeyType key; KeyType key;
for (key = min_key; key <= max_key; ++key) for (key = min_key;; ++key)
{ {
to_keys_data.insert(key); to_keys_data.insert(key);
@ -205,6 +210,8 @@ private:
} }
++offset; ++offset;
if (key == max_key)
break;
} }
to_keys_offsets.push_back(offset); to_keys_offsets.push_back(offset);

View File

@ -0,0 +1 @@
([18446744073709551615],[0])

View File

@ -0,0 +1,2 @@
SELECT mapPopulateSeries([0xFFFFFFFFFFFFFFFF], [0], 0xFFFFFFFFFFFFFFFF);
SELECT mapPopulateSeries([toUInt64(1)], [1], 0xFFFFFFFFFFFFFFFF); -- { serverError 128 }