Repository navigation
Reject NaN and infinite coordinates in polygon dictionaries - #106423
Conversation
A polygon dictionary built from source data containing `NaN` or infinite
point coordinates could fail the consistency check in
`SlabsPolygonIndex::indexBuild` and throw a `LOGICAL_ERROR` ("Error
occurred while building polygon index"). Non-finite coordinates break the
ordering assumptions of the scanline index construction (`std::sort` and
`std::unique` over `sorted_x` give undefined results for `NaN`, and
`Float64` values that overflow to infinity when cast to the `Float32`
coordinate type corrupt the index the same way).
Query points are already validated for `NaN`/infinity in `extractPoints`,
but the polygons used to build the index were not. Validate them in
`addNewPoint`, which is the single chokepoint for both the tuple and array
point representations, and reject non-finite components with a
`BAD_ARGUMENTS` exception instead of producing a logical error. Checking
after the cast to the coordinate type also catches finite `Float64` values
that overflow to infinity.
Also fix a double whitespace in the index-build error message.
CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=bb40bf2d712e3638ba51a89f9f64a05c5bfffbef&name_0=MasterCI&name_1=Stress%20test%20%28experimental%2C%20serverfuzz%2C%20arm_msan%29
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Workflow [PR], commit [34c8594] Summary: ✅
AI ReviewSummaryThis PR rejects non-finite polygon dictionary source coordinates before building polygon indexes and adds regression coverage for Findings❌ Blockers
Final VerdictStatus: ❌ Block Minimum required action: move polygon source coordinate validation before the |
|
These changes are the same in: #105583 Maybe it worth checking if the tests here cover new edge cases |
…ary-nan-inf-coordinates
… to 04318 Address review: the validation in `addNewPoint` runs after the cast to the `Coord` (`Float32`) type, so a finite `Float64` coordinate that overflows to infinity when narrowed (for example `1e39`) must also be rejected. Add a dictionary-load case asserting `BAD_ARGUMENTS` for it, which locks in the cast-after-validation ordering. Also renumber the test from `04299` to `04318` to avoid the crowded `04299` prefix after merging master. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Merged latest Review feedback: Added a third dictionary-load case covering a finite Empirical verification (locally built binary,
CI failures (both unrelated to this change):
|
|
@groeneai, the The other failure ( |
| throw Exception(ErrorCodes::BAD_ARGUMENTS, | ||
| "PolygonDictionary polygon point component must not be NaN"); | ||
|
|
||
| if (std::isinf(x) || std::isinf(y)) |
There was a problem hiding this comment.
The overflow case is still checked after handlePointsReprByArrays and handlePointsReprByTuples have narrowed the source Float64 to Coord with static_cast<IPolygonDictionary::Coord>. For a value such as 1e39, that conversion is outside the range of Float32, so the behavior of the conversion itself is not defined by C++; this check only works if the compiler and target happen to produce infinity. That means the PR's promised BAD_ARGUMENTS exception for finite values that overflow to Coord is not guaranteed. Please validate the original Float64 with std::isfinite and explicit Coord bounds before narrowing, then cast only after the value is known representable.
|
@alexey-milovidov, opened #106574 with a fix for the Root cause: Fix: extend Verified locally: 20/20 passes with |
|
@Ergus comparison done. The two PRs are functionally equivalent for the source fix (both add Recommendation: close #105583 in favour of this PR, since alexey-milovidov is actively keeping it merge-ready. I'll close mine after this comment. If the layout-split / clean-reload cases are worth keeping, happy to port them onto Session: cron:clickhouse-ci-task-worker:20260605-162600 |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 9/11 (81.82%) | Lost baseline coverage: none · Uncovered code |
The "Test Regular Union Stream" subtest spawns
SELECT a FROM t_streaming_test UNION ALL SELECT a FROM t_streaming_test STREAM
against a table that already contains one row (`'started'`, `0`). Both
`UNION ALL` sources scan that row and emit one `started` line each, so the
expected output starts with two `started` lines before any post-INSERT
data arrives.
The test previously synchronized with `read_until "$fifo_1" "started"`,
which returns after the FIRST `started` is observed. There is no
ordering guarantee between the two `UNION ALL` sources, so the regular
side's `started` could still be in flight when the test issues its
`INSERT`s. When that happens the streaming side emits a post-INSERT row
(`0`) into the FIFO before the regular side's `started` reaches stdout,
producing `started\n0\nstarted\n0\n1` instead of the reference
`started\nstarted\n0\n0\n1`. The race widens under `distributed plan` +
`s3 storage` because of the higher and more variable scheduling latency
of those configurations, which is exactly where CI saw the failures
(report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106423&sha=c63e3b252e8a6bd504220f99031f9ba16a95ce09&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20distributed%20plan%2C%20s3%20storage%2C%20parallel%29
PR: ClickHouse#106423).
This patch extends `read_until` in `streaming.lib` with an optional
target-count argument (defaults to 1, preserving existing callers) and
updates the `Test Regular Union Stream` subtest to wait for both
`started` markers before issuing the INSERTs, so the post-INSERT rows
are appended in a deterministic position relative to both source rows.
Verified locally: 20/20 passes with random settings disabled, 1/1 with
default randomization.
Caused by: ClickHouse#96130
Related: ClickHouse#106423
A polygon dictionary built from source data containing
NaNor infinite point coordinates could fail the consistency check inSlabsPolygonIndex::indexBuildand throw aLOGICAL_ERROR("Error occurred while building polygon index"). This was hit by the server fuzzer in the stress test on master.Non-finite coordinates break the ordering assumptions of the scanline index construction:
std::sortandstd::uniqueoversorted_xgive undefined results forNaN, andFloat64values that overflow to infinity when cast to theFloat32coordinate type corrupt the index the same way.Query points are already validated for
NaN/infinity inextractPoints, but the polygons used to build the index were not. The fix validates them inaddNewPoint, the single chokepoint for both the tuple and array point representations, and rejects non-finite components with aBAD_ARGUMENTSexception instead of producing a logical error. Checking after the cast to the coordinate type also catches finiteFloat64values that overflow to infinity.Also fixes a double whitespace in the index-build error message.
CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=bb40bf2d712e3638ba51a89f9f64a05c5bfffbef&name_0=MasterCI&name_1=Stress%20test%20%28experimental%2C%20serverfuzz%2C%20arm_msan%29
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a logical error when building a polygon dictionary from source data containing
NaNor infinite point coordinates. Such coordinates are now rejected with a clear error.🤖 Generated with Claude Code
Version info
26.6.1.437