Skip to content

Cherry pick #131269 to 26.3: Reject negative and overflowing values of Seconds settings - #131469

Merged
robot-clickhouse-ci-1 merged 6 commits into
backport/26.3/131269from
cherrypick/26.3/131269
Nov 15, 2026
Merged

robot-clickhouse-ci-1 merged 6 commits into
backport/26.3/131269from
cherrypick/26.3/131269

Conversation

@robot-ch-test-poll2

Copy link
Copy Markdown
Contributor

Original pull-request #131269

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

groeneai and others added 5 commits November 13, 2026 09:35
`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 #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 #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]>
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]>
…ings

Reject negative and overflowing values of `Seconds` settings
@robot-ch-test-poll2 robot-ch-test-poll2 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request labels Nov 13, 2026
Resolve the conflicts of #131269 for 26.3.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator

The only code conflict is the type name in float64AsSecondsToTimespan (26.3 still uses Poco::Timespan::TimeDiff), so I applied the same change with that name. I left the gtest_settings.cpp additions out: both of them go through SettingFieldSeconds::parseFromString, which on 26.3 does not call float64AsSecondsToTimespan (that came with #112757, which is not on 26.3), so they would fail there. The server still rejects such values from a client: it applies the settings it receives through the checked Field path, so an unpatched 26.3.60.2 client sending --max_execution_time=-1 gets BAD_ARGUMENTS from the patched server. 04058, 04201, 04327 and test_async_insert.py do not exist on 26.3; 02294, 02466 and 03000 apply as on master.

On the 26.3 tree (clang-21, debug) the existing settings gtests pass, and 02294_decimal_second_errors, 02466_distributed_query_profiler and 03000_too_big_max_execution_time_setting pass 10 of 10 with random settings. For a user whose profile has max_execution_time = 5 MAX 60, SET max_execution_time = -1 and SET max_execution_time = 9223372036854.775 now fail with BAD_ARGUMENTS, and -1 is rejected the same way as a client option and as an HTTP parameter. The official 26.3.60.2 accepts -1, and after SET max_execution_time = 9223372036854.775 the next query fails at once with Timeout exceeded ... maximum: -9223372036854775 ms.

I cannot push to cherrypick/26.3/131269. The merge is on my fork, its first parent is this PR's head 70047a956b4b and its second is backport/26.3/131269, so applying it is a fast-forward:

git fetch https://github.com/groeneai/ClickHouse.git groeneai/resolve-26.3-cherrypick-131269
git push origin FETCH_HEAD:cherrypick/26.3/131269

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Applied @groeneai's resolution as a fast-forward (d7f9a7f38743, parents: this PR's head 70047a956b4b and backport/26.3/131269 ecad7a83b35e). Against backport/26.3/131269 it changes only src/Core/SettingsFields.cpp (the original fix, using the Poco::Timespan::TimeDiff name that 26.3 has) and the 02294, 02466 and 03000 tests, which match the original PR's changes exactly. As explained above, the gtest_settings.cpp additions are left out because they depend on #112757, which is not on 26.3.

@robot-clickhouse-ci-1
robot-clickhouse-ci-1 merged commit 70b479b into backport/26.3/131269 Nov 15, 2026
2 checks passed
@robot-clickhouse-ci-1
robot-clickhouse-ci-1 deleted the cherrypick/26.3/131269 branch November 15, 2026 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants