Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logical error in function greatest #29334

Closed
alexey-milovidov opened this issue Sep 24, 2021 · 2 comments · Fixed by #29454
Closed

Logical error in function greatest #29334

alexey-milovidov opened this issue Sep 24, 2021 · 2 comments · Fixed by #29454
Assignees
Labels
fuzz Problem found by one of the fuzzers

Comments

@alexey-milovidov
Copy link
Member

Describe the bug

SELECT * FROM system.data_skipping_indices WHERE (table = 'alter_index_test') AND greatest(greatest(NULL, NULL, greatest(greatest(greatest(-2), '9223372036854775806', sleep(1), NULL), NULL), '102.5', NULL), greatest('-9223372036854775808', NULL), greatest(greatest(NULL), NULL, '0.0000065536', NULL)) AND (database = currentDatabase())
Cannot capture 4 columns because function greatest has 0 arguments.: while executing 'FUNCTION greatest(greatest(-2) :: 8, '9223372036854775806' :: 9, sleep(1) :: 6, NULL : 7) -> greatest(greatest(-2), '9223372036854775806', sleep(1), NULL) Nullable(Nothing) : 14'. (LOGICAL_ERROR)

How to reproduce
Always reproduced.

@alexey-milovidov alexey-milovidov added the fuzz Problem found by one of the fuzzers label Sep 24, 2021
@alexey-milovidov
Copy link
Member Author

It is reproduced if short circuit evaluation is enabled:

SELECT 1 AND greatest(sleep(0))

@Avogar
Copy link
Member

Avogar commented Sep 27, 2021

The bug is in LeastGreatestOverloadResolver, it passes empty list of argument types to FunctionToFunctionBaseAdaptor:

DataTypes argument_types;
/// More efficient specialization for two numeric arguments.
if (arguments.size() == 2 && isNumber(arguments[0].type) && isNumber(arguments[1].type))
return std::make_unique<FunctionToFunctionBaseAdaptor>(SpecializedFunction::create(context), argument_types, return_type);
return std::make_unique<FunctionToFunctionBaseAdaptor>(
FunctionLeastGreatestGeneric<kind>::create(context), argument_types, return_type);

Will fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fuzz Problem found by one of the fuzzers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants