Repository navigation
Conversation
The polygon dictionary load path called `addNewPoint` with whatever `Float64` value the source column produced. `SlabsPolygonIndex` then sorted those x-coordinates with `::sort` and deduped with `std::unique`, both of which are undefined when the input contains a `NaN`. The slab walker would later end up with edge endpoints that did not match `sorted_x[l]` / `sorted_x[r]`, fire the invariant check at `PolygonDictionaryUtils.cpp:188`, and abort the server with a `LOGICAL_ERROR` (`Error occurred while building polygon index. Edge ... but found ...`). The query-side path in `IPolygonDictionary::extractPoints` already rejects `NaN` and infinite components with `BAD_ARGUMENTS`. Mirror the same check on the build-side, in `addNewPoint`, so a malformed source table fails at load with a clear user-facing error instead of aborting the server inside the index builder. Add `04273_polygon_dict_nan_inf_rejected` to lock the contract in for both `POLYGON_INDEX_EACH` and `POLYGON_INDEX_CELL`, plus a follow-up sanity reload to confirm a clean source still loads. Reproducer (before the fix this aborts the server): INSERT INTO src VALUES ([[[(0., 0.), (1., 0.), (nan, 1.), (0., 1.), (0., 0.)]]], 1); SYSTEM RELOAD DICTIONARY d; Surfaced by the server-side AST fuzzer mutating `04204_polygon_dict_bytes_allocated.sql` into inserts like `(cx, cy + nan)`. See CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=1b384725455cdbaa49114566ba6b6e25f15809ed&name_0=MasterCI&name_1=Stress%20test%20%28experimental%2C%20serverfuzz%2C%20arm_tsan%29
Pre-PR validation gate(a) Deterministic repro? Yes: CREATE TABLE src (polygon Array(Array(Array(Tuple(Float64, Float64)))), city_id UInt32) ENGINE = Memory;
INSERT INTO src VALUES ([[[(0., 0.), (1., 0.), (nan, 1.), (0., 1.), (0., 0.)]]], 1);
INSERT INTO src VALUES ([[[(0., 0.), (1., 0.), (1., 1.), (0., 1.), (0., 0.)]]], 2);
CREATE DICTIONARY d (...) ... LAYOUT(POLYGON_INDEX_EACH());
SYSTEM RELOAD DICTIONARY d;On a debug build at master without this fix, this aborts the server with (b) Root cause explained? Yes. (c) Fix matches root cause? Yes. The fix rejects non-finite vertex components at load time, before they reach the index builder. This is the same boundary already used by the query-side path (d) Test intent preserved? / new tests added? New test (e) Demonstrated in both directions? Yes.
(f) Fix is general? Yes.
CIDBSingle hit in the last 90 days, triggered when the AST fuzzer mutated cc @groeneai |
|
Workflow [PR], commit [98ac93f] Summary: ✅
AI ReviewSummaryThis PR rejects non-finite polygon dictionary vertices during load, before they can reach the slab index builder. The validation is placed on the shared polygon point ingestion path, so the tuple path exercised by the regression test and the array path used by existing polygon dictionary tests go through the same guard; the changelog category and entry match the bug-fix scope. Final VerdictStatus: ✅ Approve |
|
Bugfix validation FAIL update. Investigated.
The master binary aborts inside the dictionary Same framework limitation we hit in:
Two options:
@vdimir @vitlibar, which do you prefer? I'll push the PR-body edit either way. |
|
@groeneai check the failing tests |
|
Checked all failing tests on commit
Plan: rebase on master to pick up the revert, then the only remaining failing check should be the |
Ergus
left a comment
There was a problem hiding this comment.
The fix is fine, I get just two minor details in the tests I think must be address before merging
| CREATE TABLE polygon_src_nan | ||
| ( | ||
| polygon Array(Array(Array(Tuple(Float64, Float64)))), | ||
| city_id UInt32 |
There was a problem hiding this comment.
Why not id, polygon to conventionally read ID first like in other tests?
There was a problem hiding this comment.
Reordered columns to put city_id first in 0e39d4693d1e. Now matches the conventional source-table layout (id first, then the array attribute).
| ( | ||
| polygon Array(Array(Array(Tuple(Float64, Float64)))), | ||
| city_id UInt32 | ||
| ) ENGINE = Memory; |
There was a problem hiding this comment.
Switched the source table to MergeTree ORDER BY city_id in 0e39d4693d1e. The dictionary itself already had PRIMARY KEY polygon; now the source table also has a primary key on the id column.
Address @Ergus inline comments on 04273_polygon_dict_nan_inf_rejected: put the id column first to follow the conventional source-table column order in other tests, and use a `MergeTree` source table with a primary key on `city_id` instead of `Memory`. Dictionary definitions reference attributes by name, so no other adjustments are needed. Test still reproduces the original LOGICAL_ERROR (NaN / Inf vertex crashes `SlabsPolygonIndex::indexBuild`) when the fix in `PolygonDictionary::addNewPoint` is removed, and still passes with the fix.
|
@Ergus addressed both inline comments in 0e39d46:
Verified the test still reproduces the original LOGICAL_ERROR before the fix and passes with it. Ready for re-review. |
|
@groeneai merge with master |
…n-dict-nan-inf-validation
|
@PedroTadim merged master into the branch. New HEAD |
|
@groeneai can you check the CI failures, are they related to this PR? |
|
@PedroTadim both failures are unrelated to this PR.
Regression test PR is approved and otherwise green. |
|
@groeneai I've told you a million times to stop pinging me. Please make a special note about it. Do not ping @Algunenano for anything. |
|
@groeneai get the updated changes in master (merge) and trigger CI again. |
…n-dict-nan-inf-validation
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 8/8 (100.00%) | Lost baseline coverage: none · Uncovered code |
CI ledger — covered SHA:
|
|
Closing in favour of #106423 (alexey-milovidov, "Reject NaN and infinite coordinates in polygon dictionaries"). The src/Dictionaries/PolygonDictionary.cpp fix is functionally equivalent (same Session: cron:clickhouse-ci-task-worker:20260605-162600 |
The polygon dictionary load path called
addNewPointwith whateverFloat64value the source column produced.SlabsPolygonIndexthen sorted those x-coordinates with::sortand deduped withstd::unique, both of which are undefined when the input contains aNaN. The slab walker would later end up with edge endpoints that did not matchsorted_x[l]/sorted_x[r], fire the invariant check atPolygonDictionaryUtils.cpp:188, and abort the server with aLOGICAL_ERROR(Error occurred while building polygon index. Edge ... but found ...).The query-side path in
IPolygonDictionary::extractPointsalready rejectsNaNand infinite components withBAD_ARGUMENTS. This change mirrors the same check on the build-side, inaddNewPoint, so a malformed source table fails at load with a clear user-facing error instead of aborting the server inside the index builder.tests/queries/0_stateless/04273_polygon_dict_nan_inf_rejected.sqlcovers bothPOLYGON_INDEX_EACHandPOLYGON_INDEX_CELL, plus a follow-up clean reload to confirm a sanitised source still loads.Local reproducer (before the fix this aborts the server in a debug build):
Surfaced by the server-side AST fuzzer mutating
04204_polygon_dict_bytes_allocated.sqlinto inserts like(cx, cy + nan).CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=1b384725455cdbaa49114566ba6b6e25f15809ed&name_0=MasterCI&name_1=Stress%20test%20%28experimental%2C%20serverfuzz%2C%20arm_tsan%29
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Polygon dictionaries with
LAYOUT(POLYGON_INDEX_EACH())orLAYOUT(POLYGON_INDEX_CELL())now reject source rows whose polygon vertex coordinates containNaNor infinity at load time withBAD_ARGUMENTS, instead of aborting the server inside the slab index builder.Documentation entry for user-facing changes