Skip to content

Fix UB in FunctionArrayElement::executeGenericConst(...)#19336

Closed
tavplubix wants to merge 2 commits intomasterfrom
tavplubix-patch-2
Closed

Fix UB in FunctionArrayElement::executeGenericConst(...)#19336
tavplubix wants to merge 2 commits intomasterfrom
tavplubix-patch-2

Conversation

@tavplubix
Copy link
Copy Markdown
Member

@tavplubix tavplubix commented Jan 20, 2021

I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Detailed description / Documentation draft:
https://clickhouse-test-reports.s3.yandex.net/19091/0507a38ec639e5eeba78f020ff2fc2d3d3447a0d/fuzzer_ubsan/report.html#fail1
Fixes #19305

@robot-clickhouse robot-clickhouse added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jan 20, 2021
@alexey-milovidov
Copy link
Copy Markdown
Member

@tavplubix I've made another fix in #19347. It looks more complete.

else if (index.getType() == Field::Types::Int64)
ArrayElementGenericImpl::vectorConst<true>(
col_nested, col_array->getOffsets(), -safeGet<Int64>(index) - 1, *col_res, builder);
col_nested, col_array->getOffsets(), -(safeGet<Int64>(index) + 1), *col_res, builder);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It still has signed integer overflow when index is max positive Int64.

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.

If I understand correctly, this branch is executed only when index is negative (we call ArrayElementGenericImpl::vectorConst(...) with negative = true), so there is no signed integer overflow.

@alexey-milovidov alexey-milovidov self-assigned this Jan 21, 2021
@alexey-milovidov
Copy link
Copy Markdown
Member

Please review my PR then :)

@tavplubix tavplubix deleted the tavplubix-patch-2 branch April 1, 2021 17:14
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.

ArrayElement + ubsan

3 participants