Repository navigation
Reject negative and overflowing values of Seconds settings - #131269
alexey-milovidov merged 4 commits into
Conversation
`float64AsSecondsToTimespan` converts every user value of a `Seconds` setting (SET, query SETTINGS, profiles and constraint bounds, config files, HTTP parameters, the native protocol) into Int64 microseconds. It accepted negative values, which every consumer reads as "no limit" and which compare below any MAX settings constraint, so a constrained user could run `SET max_execution_time = -1` and escape the administrator's limit. Negatives were allowed in ClickHouse#37187 only because `drain_timeout` gave `-1` a meaning; that setting is obsolete and none of the 40 live `Seconds` settings documents a negative value. `Milliseconds` settings already reject negatives. Its range check compared the product with `Int64::max()` converted to Float64, which rounds up to 2^63, so `9223372036854.775` (product exactly 2^63) passed and the `static_cast<Int64>` overflowed: UBSan aborts, and a release build stores INT64_MIN, i.e. a negative timeout again. Use `accurate::greaterOp`, as `fieldToNumberSettingValue` does. Tests: a MAX-constraint case in 04058, the overflow value in 03000, the negative values of 02294 move to the error group, and gtests for the string parse and the native STRINGS_WITH_FLAGS wire. 02466 drops the obsolete `drain_timeout=-1` and 04327 its negative `lock_acquire_timeout` lines, which are now rejected. Closes ClickHouse#131194 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The six-line header described the `d * 1000000 < min()` branch of `float64AsSecondsToTimespan`, which no longer exists: negative values are now rejected before the range check. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 3 findings in the full pass, 0 in the delta recheck), plus my own review (row 4).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261113-110300 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261113-085902 |
|
Workflow [PR], commit [f67395c] Summary: ✅
AI ReviewSummaryReviewed #131269 at Missing context / blind spots
Final VerdictStatus: ✅ Approve. No code changes requested; remaining CI checks still apply. |
clang-tidy (`clang-analyzer-optin.core.EnumCastOutOfRange`, an error under `WarningsAsErrors`) rejects `static_cast<Flags>(0)` because 0 is not an enumerator of `BaseSettingsHelpers::Flags`, which broke `Build (arm_tidy)`. Use value-initialization, as `BaseSettings::write` does; the bytes written are the same. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…theus test `test_async_insert_flush_timeout_is_clamped` sent `wait_for_async_insert_timeout=-10000000000` and expected the wait clamp to answer 503. A negative `Seconds` value is now rejected when the URL settings are applied (400, `BAD_ARGUMENTS`), so the request never reaches the wait and nothing is queued: the case is gone and two rows arrive instead of three. The positive overflow case still covers the clamp. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units7 translation units recompiled, 7 s compile time in total, 7 of them have a recent master baseline. |
Backport #131269 to 26.10: Reject negative and overflowing values of `Seconds` settings
|
@groeneai @alexey-milovidov — title/description suggestions: Description (currently
Ignore if intentional. |
…rmat` The merge queue run failed in `Clang-tidy (changed files)`: test `SecondsOnTheWireRejectNegativeAndOverflowingValues` from #131269 passes `SettingsWriteFormat::STRINGS_WITH_FLAGS` to `Settings::read`, which is the only format now. https://github.com/ClickHouse/ClickHouse/actions/runs/43592425942/job/132440172906 Related: #131099 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Confirmed: a client or server with this change cannot connect over the native protocol to an older server whose profile has a negative |
Resolve the conflicts of #131269 for 26.9. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cherry pick #131269 to 26.9: Reject negative and overflowing values of `Seconds` settings
Resolve the conflicts of #131269 for 26.8. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve the conflicts of #131269 for 26.3. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cherry pick #131269 to 26.3: Reject negative and overflowing values of `Seconds` settings
Cherry pick #131269 to 26.8: Reject negative and overflowing values of `Seconds` settings
Backport #131269 to 26.9: Reject negative and overflowing values of `Seconds` settings
Backport #131269 to 26.8: Reject negative and overflowing values of `Seconds` settings
Backport #131269 to 26.3: Reject negative and overflowing values of `Seconds` settings
Since ClickHouse#131269 a `Seconds` setting rejects a negative or overflowing value, while every supported older release accepts and stores one, and its `TCPHandler::sendHello` sends the user's changed settings in `Hello`. `Connection::receiveHello` read them with the same strict `BaseSettings::read` the server uses for a client's query settings, so a client or an initiator with ClickHouse#131269 could not connect at all to an older server whose user or profile has e.g. `max_execution_time = -1` (`Code: 36 ... cannot be negative`). An unknown non-important setting from the server was already only a warning. `BaseSettings::read` gets an opt-in `skip_invalid_values`: in the `STRINGS_WITH_FLAGS` branch the value string is read first, and if parsing it throws `BAD_ARGUMENTS` or a parse error (`isParseError`, the same classification `insertPostgreSQLValue` uses) for a non-important setting, the field is reset to its default and a warning is logged. The reset is needed because `SettingFieldNonZeroUInt64::parseFromString` assigns before it throws. Any other exception, and an `IMPORTANT` setting (the rule the unknown-setting branch already applies), still fail the read. Only `Connection::receiveHello` opts in: the settings in `Hello` are advisory for the client (the server applies its own profile to every query), while the server's read of a client's settings must keep rejecting `-1` (ClickHouse#131194). Tests: a gtest for the tolerant read (a rejected `Seconds` value, a zero `NonZeroUInt64`, an unparsable `Bool`, a valid setting after them, the strict default, an `IMPORTANT` flag, and an unknown enum name (`load_balancing`), which still fails the tolerant read), and a `test_backward_compatibility` case with a 25.3 node: a user with `max_execution_time = -1`, reached by the tested client and by a tested `remote()` initiator. The test uses `query_and_get_answer_with_error` because the client prints the warning on stderr. Closes ClickHouse#131506 Related ClickHouse#131269, ClickHouse#131194 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #131194
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Settings of type
Seconds(for examplemax_execution_timeorlock_acquire_timeout) now reject a negative value withBAD_ARGUMENTS. A negativemax_execution_timemeant no limit and passed aMAXconstraint; a value whose microseconds round to2^63(for example9223372036854.775) was stored as a large negative number; it is rejected too. Before upgrading, remove negative values of these settings from configuration files, settings profiles, users and table definitions, and letDistributedasync insert queues drain; otherwise the server can fail to start, a user or table fails to load, or a queued insert is never sent.Description
On 26.10.2.103, a user whose profile has
max_execution_time MAX 60canSET max_execution_time = -1or= 9223372036854.775(read back negative); a negative value means no limit, so queries can run past the administrator's limit.float64AsSecondsToTimespanconverts every user value into aSecondsfield (SET, querySETTINGS, profiles, constraints, config files, HTTP, native protocol). It accepted negatives, and its range check compared withInt64::max()rounded to2^63, so a product of2^63passed and thestatic_cast<Int64>overflowed (UBSan aborts on master). It now rejectsd < 0(-0.0stays0) and checks the range withaccurate::greaterOp.None of the 40 live
Secondssettings documents a negative value; the one that did,drain_timeout(-1, why #37187 allowed negatives), is obsolete. Four tests that used negatives are updated.Measured on upgrade with a negative value: in
users.xmlthe server does not start (CANNOT_LOAD_CONFIG); in a SQL settings profile it does not start after a clean shutdown, and after an unclean one the profile is skipped with a logged error, so a user that gotreadonly = 1from it loses it; a SQL user cannot log in, and after a clean shutdownSHOW USERSfails until it is dropped; a MergeTree table does not attach; aDistributedqueue file fails on every retry and holds back that table's later inserts. AMAX-only constraint still accepts0, which also means no limit;MIN 1or<disallowed>0</disallowed>forbids it.Tests:
04058_check_constraints_for_profiles(Test 8),03000_too_big_max_execution_time_settingand two gtests (string parse, nativeSTRINGS_WITH_FLAGS) fail before the change.Workflow [PR]
Sync PR [sync-upstream/pr/131269]
Version info
26.11.1.2257-master(included in26.11and later)26.10.5.4,26.9.29.6,26.8.38.6,26.3.65.4