Skip to content

Cap row counts at SIZE_MAX on 32-bit targets - #36

Merged
serprex merged 2 commits into
ClickHouse:mainfrom
iliaal:ch-32bit-row-limit
Nov 22, 2026
Merged

serprex merged 2 commits into
ClickHouse:mainfrom
iliaal:ch-32bit-row-limit

Conversation

@iliaal

@iliaal iliaal commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

CHC_MAX_NUM_ROWS defaults to 10^12, which is above SIZE_MAX on 32-bit targets. Block row counts, Array totals and LowCardinality dictionary sizes between 2^32 and 10^12 pass the check and are then cast to size_t.

On i386, an Array(UInt8) row whose offset is 2^32 + 1 decodes one nested value, but its offset still says 2^32 + 1. A caller walking the offsets reads past the nested column. A block that declares 2^32 + 1 rows comes back with 1 row and no error.

The default is now clamped to SIZE_MAX, and an #error rejects an override that doesn't fit size_t. 64-bit builds keep 10^12.

CHC_MAX_NUM_ROWS defaults to 10^12, above SIZE_MAX on 32-bit targets, so
block row counts, Array totals & LowCardinality dictionary sizes between
2^32 & 10^12 passed the check & were then narrowed to size_t. An
Array(UInt8) row whose offset is 2^32 + 1 decoded 1 nested value while
its offset still claimed 2^32 + 1, & a block declaring 2^32 + 1 rows
came back with 1 row & no error.

Clamp the default to SIZE_MAX, & reject an override that exceeds it.
Comment thread test/test_wire_errors.c Outdated
test_rows_past_size_t(void)
{
current_test = "rows_past_size_t";
#if SIZE_MAX < UINT64_MAX

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.

since CI doesn't run on 32b it's fine to omit this test

@serprex
serprex merged commit b51f892 into ClickHouse:main Nov 22, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants