Skip to content

Reject timespan setting (milliseconds/seconds) values that overflow Int64 microseconds - #112757

Merged
azat merged 1 commit into
ClickHouse:masterfrom
azat:setting-timespan-clamp-ns
Aug 2, 2026
Merged

azat merged 1 commit into
ClickHouse:masterfrom
azat:setting-timespan-clamp-ns

Conversation

@azat

@azat azat commented Jul 31, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Backward Incompatible Change

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

Reject timespan setting (milliseconds/seconds) values that overflow Int64 microseconds

Refs: #106961

Version info

  • Merged into: 26.8.1.647 (included in 26.8 and later)

@clickhouse-gh

clickhouse-gh Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5d1aed1]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_debug, parallel) FAIL
04648_geohashes_in_box_cancellation FAIL cidb

AI Review

Summary

This PR makes Seconds/Milliseconds settings reject values whose conversion to Int64 microseconds would overflow, and routes SettingFieldSeconds::parseFromString through the existing checked helper so huge floating-point inputs stop reaching undefined behavior. The implementation is internally consistent across Field, string, and legacy binary entry points, but it still introduces an upgrade and mixed-version compatibility break for already-persisted oversized settings without a compatibility path.

PR Metadata
  • Changelog category: Backward Incompatible Change is correct for the actual behavior change.
  • Changelog entry: required for this category. The current text explains what changed, but it does not tell users that upgrade can now fail while loading old profile/config values or while receiving legacy settings from an older peer that still carries a wrapped value in memory.
  • Exact replacement text:

ClickHouse now rejects Seconds and Milliseconds settings whose values overflow Int64 microseconds. Before upgrading, remove or lower any oversized values in configs, profiles, or client settings, because values that previously wrapped (for example connection_pool_max_wait_ms = 18446744073709551615) now fail with BAD_ARGUMENTS.

Findings

❌ Blockers

  • [src/Core/SettingsFields.cpp:420] [dismissed by author -- https://github.com/Reject timespan setting (milliseconds/seconds) values that overflow Int64 microseconds #112757#discussion_r3691442294] The new microsecondsFromUnits check changes the contract for existing Seconds/Milliseconds settings everywhere they are re-parsed, including config/profile strings and legacy settings exchange. A deployment that currently persists a wrapped value such as connection_pool_max_wait_ms = 18446744073709551615 will now start throwing BAD_ARGUMENTS on upgrade or when a newer node receives that setting from an older peer. I still consider this real because the change ships no compatibility setting or staged migration path for already-persisted values. Suggested fix: add a compatibility path via SettingsChangesHistory.cpp or a dedicated setting, or keep loading old persisted values while rejecting only newly assigned oversized values.
Final Verdict

Needs changes. The overflow fix itself looks sound, but I would not approve it without a compatibility or migration path for already-persisted oversized Seconds/Milliseconds settings and a changelog entry that tells operators how to prepare for upgrade.

@clickhouse-gh clickhouse-gh Bot added the pr-backward-incompatible Pull request with backwards incompatible changes label Jul 31, 2026
@Algunenano Algunenano self-assigned this Jul 31, 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.

Makes sense to me. Another way to handle it would be via SettingsQuirks, but that's less clean

@azat

azat commented Jul 31, 2026

Copy link
Copy Markdown
Member Author

Quirks are for different things, we can clamp values instead here, but it will be nice to avoid this and simply throw instead of accepting invalid values

Int64 SettingFieldTimespan<unit_>::microsecondsFromUnits(UInt64 units)
{
constexpr std::string_view unit_name = unit == SettingFieldTimespanUnit::Millisecond ? "milliseconds" : "seconds";
if (units > static_cast<UInt64>(std::numeric_limits<Int64>::max() / static_cast<Int64>(microseconds_per_unit)))

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.

This changes the contract for every Seconds/Milliseconds setting, including persisted profile/config values and legacy binary settings from older clients, but there is still no compatibility path for upgraded deployments. A node that currently accepts <connection_pool_max_wait_ms>18446744073709551615</connection_pool_max_wait_ms> (storing the wrapped -1 ms value) will start throwing BAD_ARGUMENTS during settings parsing after this PR. For backward-incompatible validation on existing settings we normally either gate the new behavior behind a setting / SettingsChangesHistory.cpp entry or scope it so old persisted values keep loading.

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.

This is the intention for now.

@azat
azat force-pushed the setting-timespan-clamp-ns branch from 375435c to 204d5da Compare July 31, 2026 16:12
@azat

azat commented Aug 1, 2026 •

Copy link
Copy Markdown
Member Author

Fast test (arm_darwin)

UPD: I am not sure it was it, since part of the log is missing, and the last entries are from runned tests, will rebase

…nt64 microseconds

The `UInt64 -> microseconds` conversion multiplied by the unit factor
unchecked, wrapping mod 2^64: `SET connection_pool_max_wait_ms = 2^61`
silently stored 0, and `UInt64` max stored -1 ms. Every integer producer
(`Field`/`SET`, `parseFromString`, `readBinary`) now throws `BAD_ARGUMENTS`,
the same bound the `Float64` path enforces via `float64AsSecondsToTimespan`.
`SettingFieldSeconds::parseFromString` had a second bug, an out-of-range
`Float64`-to-`Int64` cast (UB) for values like 1e30; it now goes through
`float64AsSecondsToTimespan` like the `Field` path.

Refs: ClickHouse#106961

Co-Authored-By: Claude Fable 5 <[email protected]>
@azat
azat force-pushed the setting-timespan-clamp-ns branch from 204d5da to 5d1aed1 Compare August 1, 2026 13:30
@clickhouse-gh

clickhouse-gh Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.50% 86.50% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 78.70% 78.70% +0.00%

Changed lines: Changed C/C++ lines covered: 42/43 (97.67%) · Uncovered code

Full report · Diff report

@azat

azat commented Aug 2, 2026

Copy link
Copy Markdown
Member Author

@azat
azat enabled auto-merge August 2, 2026 21:35
@azat
azat added this pull request to the merge queue Aug 2, 2026
Merged via the queue into ClickHouse:master with commit 619adf6 Aug 2, 2026
177 of 179 checks passed
@azat
azat deleted the setting-timespan-clamp-ns branch August 2, 2026 22:16
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 2, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Aug 10, 2026
ClickHouse#112757 made SettingFieldTimespan reject millisecond values that overflow
Int64 microseconds, so a configured value can no longer wrap negative in
storage. The negative and unsigned-huge cases are still worth pinning
because several Keeper sites hold the count in an unsigned type, so the
comments now state that invariant instead of the storage path.

Co-Authored-By: Claude Fable 5 <[email protected]>
alexey-milovidov added a commit that referenced this pull request Nov 22, 2026
Conflicts in `src/Client/Connection.cpp`, `src/Core/BaseSettings.h`,
`src/Core/Settings.cpp`, `src/Core/Settings.h` and
`src/Core/tests/gtest_settings.cpp` are resolved by taking the 26.3 side and
re-applying the change of #131636 on top of the 26.3 API
(`read(in, format, skip_invalid_values)`, `isParseError` from
`Processors/Formats/IRowInputFormat.h`).

Adaptation for 26.3: here `SettingFieldSeconds::parseFromString` does not
validate the value (#112757 is not on 26.3), so reading `max_execution_time = -1`
from the server's `Hello` succeeds and the client fails later, when it applies
the value as a `Field`. With `skip_invalid_values`, `BaseSettings::read` now
also re-assigns the parsed value as a `Field`, so such a value is skipped with
a warning, as on master. The strict read (the server side) is unchanged.
The gtest is adapted accordingly; master-only gtests are not carried over.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backward-incompatible Pull request with backwards incompatible changes 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.

3 participants