Skip to content

Fix SIGSEGV for external GROUP BY and overflow row#23962

Merged
alexey-milovidov merged 2 commits intoClickHouse:masterfrom
azat:external-group-by-overflow-row-fix
May 10, 2021
Merged

Fix SIGSEGV for external GROUP BY and overflow row#23962
alexey-milovidov merged 2 commits intoClickHouse:masterfrom
azat:external-group-by-overflow-row-fix

Conversation

@azat
Copy link
Copy Markdown
Member

@azat azat commented May 8, 2021

Changelog category (leave one):

  • Bug Fix

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fix SIGSEGV for external GROUP BY and overflow row (i.e. queries like SELECT FROM GROUP BY WITH TOTALS SETTINGS max_bytes_before_external_group_by>0, max_rows_to_group_by>0, group_by_overflow_mode='any', totals_mode='before_having')

Detailed description / Documentation draft:
Overflow row is used for GROUP BY if all of the above is true:

  • WITH TOTALS is requested
  • max_rows_to_group_by > 0
  • group_by_overflow_mode = any
  • totals_mode != after_having_exclusive

And in case of overflow row and external GROUP BY, once the temporary
file dumps to disk it resets without_key data variant to nullptr, so any
subsequent dump to disk will cause SIGSEGV.

Fix this, by recreating without_key data variant after dumping to disk,
instead of reseting to nullptr.

And also add sanity check (LOGICAL_ERROR) to make error more
deterministic in case of such error.

Found with fuzzer 1.

Overflow row is used for GROUP BY if all of the above is true:
- WITH TOTALS is requested
- max_rows_to_group_by > 0
- group_by_overflow_mode = any
- totals_mode != after_having_exclusive

And in case of overflow row and external GROUP BY, once the temporary
file dumps to disk it resets without_key data variant to nullptr, so any
subsequent dump to disk will cause SIGSEGV.

Fix this, by recreating without_key data variant after dumping to disk,
instead of reseting to nullptr.

And also add sanity check (LOGICAL_ERROR) to make error more
deterministic in case of such error.

Found with fuzzer [1].

  [1]: https://clickhouse-test-reports.s3.yandex.net/23929/e7027e052998540ee660d186727e20f9555b729d/fuzzer_ubsan/report.html#fail1
@robot-clickhouse robot-clickhouse added the pr-bugfix Pull request with bugfix, not backported by default label May 8, 2021
@alexey-milovidov alexey-milovidov self-assigned this May 8, 2021
@alexey-milovidov
Copy link
Copy Markdown
Member

Is total row calculated correctly if data was flushed to disk?

Change aggregation function to uniqCombined() to check this.
@azat
Copy link
Copy Markdown
Member Author

azat commented May 8, 2021

Is total row calculated correctly if data was flushed to disk?

Yes (I've changed the aggregate function in test to uniqCombined)

@azat
Copy link
Copy Markdown
Member Author

azat commented May 10, 2021

Functional stateless tests (release, DatabaseReplicated) — fail: 1, passed: 2920, skipped: 108
Integration tests (thread) — Timeout, fail: 1, passed: 945, flaky: 3

Unrelated

Yandex third-party checks (only for Yandex employees)

Broken in upstream/master

@alexey-milovidov alexey-milovidov merged commit ab33b80 into ClickHouse:master May 10, 2021
@azat azat deleted the external-group-by-overflow-row-fix branch May 10, 2021 21:35
kitaisreal added a commit that referenced this pull request May 11, 2021
Backport #23962 to 21.3: Fix SIGSEGV for external GROUP BY and overflow row
kitaisreal added a commit that referenced this pull request May 11, 2021
Backport #23962 to 21.5: Fix SIGSEGV for external GROUP BY and overflow row
kitaisreal added a commit that referenced this pull request May 11, 2021
Backport #23962 to 21.4: Fix SIGSEGV for external GROUP BY and overflow row
alexey-milovidov added a commit that referenced this pull request Jun 12, 2021
Backport #23962 to 20.8: Fix SIGSEGV for external GROUP BY and overflow row
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants