Fix user supplied witness version check in bech32Encode function by george-larionov · Pull Request #102147 · ClickHouse/ClickHouse · GitHub
Skip to content

Fix user supplied witness version check in bech32Encode function#102147

Merged
alexey-milovidov merged 3 commits into
masterfrom
fix-bech32Encode-witness-version-check
Apr 26, 2026
Merged

Fix user supplied witness version check in bech32Encode function#102147
alexey-milovidov merged 3 commits into
masterfrom
fix-bech32Encode-witness-version-check

Conversation

@george-larionov

@george-larionov george-larionov commented Apr 8, 2026

Copy link
Copy Markdown
Member

Fix user supplied witness version value check. Resolves #101839.

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

@george-larionov george-larionov changed the title fixing user supplied witness version check Fix user supplied witness version check Apr 8, 2026
@george-larionov george-larionov changed the title Fix user supplied witness version check Fix user supplied witness version check in bech32Encode function Apr 8, 2026
@george-larionov george-larionov marked this pull request as ready for review April 8, 2026 23:05
@clickhouse-gh

clickhouse-gh Bot commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Apr 8, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

The Fast test (arm_darwin) failure is unrelated to this PR — the fix is in #102184.

@Algunenano Algunenano self-assigned this Apr 9, 2026

@Algunenano Algunenano left a comment

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.

Looks good, but it should either be "Not for changelog" (I don't see this as a real bug), or we need to add/update a tests to reflect the change

@george-larionov

Copy link
Copy Markdown
Member Author

Looks good, but it should either be "Not for changelog" (I don't see this as a real bug), or we need to add/update a tests to reflect the change

I changed it to "Not for changelog"

@alexey-milovidov

Copy link
Copy Markdown
Member

The Hung check failure is fixed by #102008 and #102010, let's update the branch

@clickhouse-gh clickhouse-gh Bot added pr-not-for-changelog This PR should not be mentioned in the changelog and removed pr-bugfix Pull request with bugfix, not backported by default labels Apr 10, 2026
Comment thread src/Functions/bech32.cpp
* It also must fit in the bech32 charset which is 5 bits (0-31), otherwise
* indexing into the CHARSET array in bech32::encode will cause a buffer overflow.
*/
auto user_witness_version = witness_version_col->getUInt(i);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Nice fix validating before static_cast<uint8_t>, but we still need a regression test for wider unsigned input types (allowed by isNativeUInt()), e.g. toUInt16(272) or toUInt64(1000).

Without this, the previous truncation bug path is not fully protected against refactors (values >255 being truncated before validation). Please add a stateless query test that passes a wider UInt type and asserts BAD_ARGUMENTS.

@clickhouse-gh

clickhouse-gh Bot commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.00% 84.00% +0.00%
Functions 90.90% 90.90% +0.00%
Branches 76.50% 76.50% +0.00%

Changed lines: 100.00% (17/17) | lost baseline coverage: 1 line(s) · Uncovered code

Full report · Diff report

@alexey-milovidov alexey-milovidov added this pull request to the merge queue Apr 26, 2026
Merged via the queue into master with commit e78de5c Apr 26, 2026
164 checks passed
@alexey-milovidov alexey-milovidov deleted the fix-bech32Encode-witness-version-check branch April 26, 2026 11:54
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 26, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

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 pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bech32Encode witness version truncated to uint8_t before range validation, bypassing >16 check

5 participants