Repository navigation
Fix undefined behavior on an out-of-range quota limit - #113178
Merged
Merged
Conversation
A quota limit of a type whose `output_denominator` is not 1 (`execution_time`, kept in nanoseconds) is scaled with floating point arithmetic and then converted to `QuotaValue` (`UInt64`) with a plain `static_cast`. Converting a `Float64` that does not fit into `UInt64` is undefined behavior, which UBSan reports as: ``` src/Parsers/Access/ParserCreateQuotaQuery.cpp:169:49: runtime error: 1.84467e+19 is outside the range of representable values of type 'unsigned long' ``` The AST fuzzer hits it regularly, e.g. on https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=80263&sha=2717d0f07a49ac6dd54318fe870ed0a3d9a2a7d1&name_0=PR&name_1=AST%20fuzzer%20%28arm_asan_ubsan%29 (#80263), and on five unrelated pull requests over the last two weeks. The scaling is moved into a new `QuotaTypeInfo::scaleToValue`, which rejects a non-finite or out-of-range result with `BAD_ARGUMENTS` before the cast. It is used both by the parser and by `QuotaTypeInfo::stringToValue`, which had the same unchecked cast. The range check uses `accurate::greaterOp` rather than a naive comparison, because `Float64(std::numeric_limits<UInt64>::max())` rounds up - the same reasoning as in `FieldVisitorConvertToNumber`.
1 task
Contributor
|
Workflow [PR], commit [2410297] Summary: ✅
AI ReviewSummaryThis PR moves quota-limit scaling into PR Metadata
### Changelog category (leave one):
- Not for changelog (changelog entry is not required)Final Verdict✅ No inline code findings. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 13/13 (100.00%) · Uncovered code |
The flaky check runs a new test many times in parallel with itself, and quotas are server-global, so the fixed name `quota_04695` collided across concurrent runs (`ACCESS_ENTITY_ALREADY_EXISTS`, `UNKNOWN_QUOTA`, and an empty result from `system.quota_limits` after a concurrent `DROP QUOTA`). Convert the test to a shell test with the quota name suffixed by the unique test database name, following `04321_multiple_quotas_per_user.sh`. https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113178&sha=7a44665199d7d4a6559d2f5809a10bc948cb7a68&name_0=PR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20flaky%20check%29 #113178 Co-Authored-By: Claude Fable 5 <[email protected]>
Manerone
approved these changes
Aug 4, 2026
alexey-milovidov
added a commit
that referenced
this pull request
Aug 4, 2026
…-ubsan-overflow Master merged a narrower fix for the same undefined behavior (`QuotaTypeInfo::scaleToValue`, from PR #113178). This branch computes the scaled value exactly from the literal text and range-checks every path, superseding that guard, so the conflict is resolved by keeping this branch's `parseMaxValue` and `stringToValue` and removing the now-unused `scaleToValue`. The new test `04695_quota_limit_out_of_range` from master is kept and passes under this branch's behavior.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
...
Documentation entry for user-facing changes
...
A quota limit of a type whose
output_denominatoris not 1 (execution_time, which is kept in nanoseconds) is scaled with floating point arithmetic and then converted toQuotaValue(UInt64) with a plainstatic_cast. Converting aFloat64that does not fit intoUInt64is undefined behavior:CREATE QUOTA q FOR INTERVAL 1 day MAX execution_time = 1e19is enough to trigger it. The AST fuzzer finds it regularly - it has failedAST fuzzer (arm_asan_ubsan)on five unrelated pull requests over the last two weeks, most recently on https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=80263&sha=2717d0f07a49ac6dd54318fe870ed0a3d9a2a7d1&name_0=PR&name_1=AST%20fuzzer%20%28arm_asan_ubsan%29The scaling is moved into a new
QuotaTypeInfo::scaleToValue, which rejects a non-finite or out-of-range result withBAD_ARGUMENTSbefore the cast. It is used both by the parser and byQuotaTypeInfo::stringToValue, which had the same unchecked cast. The range check usesaccurate::greaterOprather than a naive comparison, becauseFloat64(std::numeric_limits<UInt64>::max())rounds up - the same reasoning as the one already documented inFieldVisitorConvertToNumber.Related: #80263
Related: #103817