Skip to content

More robust protection from recursive Buffer#40640

Closed
azat wants to merge 1 commit intoClickHouse:masterfrom
azat:buffer/recursive-fix
Closed

More robust protection from recursive Buffer#40640
azat wants to merge 1 commit intoClickHouse:masterfrom
azat:buffer/recursive-fix

Conversation

@azat
Copy link
Copy Markdown
Member

@azat azat commented Aug 25, 2022

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in official stable or prestable release)

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

More robust protection from recursive Buffer (fix possible SIGSEGV for select * from system.tables when Buffer points to itself)

This fixes the following places:

  • IStorage::totalRows()
  • flushing buffer
  • StorageBuffer::mayBenefitFromIndexForIn() (lack of check for table
    existence)

And it also makes this error fatal, i.e. now you will always got
INFINITE_LOOP error, while before getQueryProcessingStage() ignores the
error.

Fixes: #40637 (cc @alexey-milovidov )

@robot-clickhouse robot-clickhouse added the pr-bugfix Pull request with bugfix, not backported by default label Aug 25, 2022
This fixes the following places:
- IStorage::totalRows()
- flushing buffer
- StorageBuffer::mayBenefitFromIndexForIn() (lack of check for table
  existence)

And it also makes this error fatal, i.e. now you will always got
INFINITE_LOOP error, while before getQueryProcessingStage() ignores the
error.

Fixes: ClickHouse#40637
Signed-off-by: Azat Khuzhin <[email protected]>
@azat azat force-pushed the buffer/recursive-fix branch from 3341511 to 5169cdb Compare August 25, 2022 20:35
@alexey-milovidov
Copy link
Copy Markdown
Member

It does not protect from two Buffer tables referencing each other, see #40643.

@alexey-milovidov alexey-milovidov self-assigned this Aug 25, 2022
@azat azat closed this Aug 25, 2022
throw Exception("Destination table is myself. Read will cause infinite loop.", ErrorCodes::INFINITE_LOOP);
auto destination = getDestinationTable();
if (destination)
return destination->mayBenefitFromIndexForIn(left_in_operand, query_context, destination->getInMemoryMetadataPtr());
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexey-milovidov could you also modify this in your PR, before it does not check that the table still exists

try
{
writeBlockToDestination(block_to_write, DatabaseCatalog::instance().tryGetTable(destination_id, getContext()));
writeBlockToDestination(block_to_write, getDestinationTable());
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexey-milovidov and this place also should be fixed in #40643 then

@azat azat deleted the buffer/recursive-fix branch August 26, 2022 07:27
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.

SegFault with "recursive" buffer table

3 participants