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

Make ASTSelectQuery::formatImpl() more robust #46889

Merged
merged 1 commit into from
Feb 26, 2023
Merged

Conversation

rschu1ze
Copy link
Member

@rschu1ze rschu1ze commented Feb 25, 2023

Fixes #45204

The problem is that ASTSelectQuery::group_by_with_grouping_sets == true should imply ASTSelectQuery::groupBy() but sometimes this wasn't the case. I added a sanity check a few months ago but had no idea how the AST became corrupt.

All crashes/exceptions were during AST fuzzing. Looking at Client/QueryFuzzer.cpp, there is a very small chance to run into the issue. In detail:

  1. In QueryFuzzer::fuzz(), we find that the AST is a ASTSelectQuery and groupBy() returns true.

  2. With small probability, we do select->group_by_with_grouping_sets = !select->group_by_with_grouping_sets; where the (default false) group_by_with_grouping_sets flips true.

  3. With small probability, we change the expression type in the following WHERE or PREWHERE if-branches.

This situation is illegal. One possibility is changing the fuzzing code to not generate it. The fuzzing code is however generic, and doesn't really care about such details. Therefore, instead add an (theoretically unnecessary) extra check to ASTSelectQuery::formatImpl() for robustness.

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Fixes #45204

The problem is that ASTSelectQuery::group_by_with_grouping_sets == true
implies ASTSelectQuery::groupBy() but sometimes this wasn't the case. I
added a sanity check a few months ago but had no idea how the AST became
corrupt.

All crashes/exceptions were during AST fuzzing. Looking at
Client/QueryFuzzer.cpp, there is a very small chance to run into the
issue. In detail:

1. In QueryFuzzer::fuzz(), we find that the AST is a ASTSelectQuery and
   groupBy() returns true.

2. With small probability, we do
     select->group_by_with_grouping_sets = !select->group_by_with_grouping_sets;
   where the (default false) group_by_with_grouping_sets flips true.

3. With small probability, we change the expression type in the
   following WHERE or PREWHERE if-branches.

This situation is illegal. One possibility is changing the fuzzing code
to not generate it. The fuzzing code is however generic, and doesn't
really care about such details. Therefore, instead add an (theoretically
unnecessary) extra check to ASTSelectQuery::formatImpl() for robustness.
@robot-ch-test-poll robot-ch-test-poll added the pr-not-for-changelog This PR should not be mentioned in the changelog label Feb 25, 2023
@evillique evillique self-assigned this Feb 25, 2023
@rschu1ze rschu1ze merged commit 97f2778 into master Feb 26, 2023
@rschu1ze rschu1ze deleted the rs/groupby-fuzz branch February 26, 2023 06:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-not-for-changelog This PR should not be mentioned in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Corrupt AST
3 participants