Skip to content

Reject POINT EMPTY in readWKT / readWKTPoint - #110692

Merged
nikitamikhaylov merged 3 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-readwkt-point-empty
Jul 22, 2026
Merged

nikitamikhaylov merged 3 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-readwkt-point-empty

Conversation

@groeneai

@groeneai groeneai commented Jul 16, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #110687

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixed readWKT and readWKTPoint returning uninitialized (scalar) or stale prior-row (vectorized) coordinates for POINT EMPTY. POINT EMPTY is now rejected with CANNOT_PARSE_TEXT, since a ClickHouse Point is a fixed Tuple(Float64, Float64) with no empty representation.

Description

POINT EMPTY is valid WKT, but boost::geometry::read_wkt accepts it without writing the coordinates or throwing. A ClickHouse Point is a fixed Tuple(Float64, Float64) with no empty representation, so the coordinates were left uninitialized (scalar, non-deterministic and MSan-flaggable) or carried over from a previous row (vectorized). LINESTRING/POLYGON/MULTIPOLYGON EMPTY were unaffected because those types have valid empty representations.

Fix: after parsing, detect the empty-point form (case- and whitespace-insensitive) and reject it with CANNOT_PARSE_TEXT. Also moved the per-row Geometry object inside the execution loop so a row that read_wkt leaves untouched cannot carry over prior-row contents.

Report: #110687 (fiddle: https://fiddle.clickhouse.com/16fc1a3e-6065-440a-b8f7-39253fbba8c6)

Version info

  • Merged into: 26.7.1.1329 (included in 26.7 and later)

POINT EMPTY is valid WKT, but a ClickHouse Point is a fixed
Tuple(Float64, Float64) with no empty representation.
boost::geometry::read_wkt accepts POINT EMPTY without writing the
coordinates or throwing, so the functions returned uninitialized
coordinates (scalar, non-deterministic, MSan-flaggable) or stale
prior-row coordinates (vectorized). Detect the empty-point form after
parsing and reject it with CANNOT_PARSE_TEXT. Also move the per-row
Geometry object inside the execution loop so a row read_wkt leaves
untouched cannot carry over prior-row contents.

Non-point empty geometries (LINESTRING/POLYGON/MULTIPOLYGON EMPTY) are
unaffected because those types have valid empty representations.

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

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Check Result
a Deterministic repro? Yes. SELECT readWKTPoint('POINT EMPTY') returns uninitialized coords every run (e.g. (2.68e-314,6.13e-310)); vectorized values('s String','POINT (11 22)','POINT EMPTY') returns stale (11,22) for the empty row.
b Root cause explained? boost::geometry::read_wkt("POINT EMPTY", g) accepts the string without writing coords or throwing. A ClickHouse Point is a fixed Tuple(Float64,Float64) with no empty representation, so g keeps uninitialized memory (first row) or the previous row's coords (later rows).
c Fix matches root cause? Yes. After parsing, detect the empty-point form and reject it with CANNOT_PARSE_TEXT; and declare Geometry inside the per-row loop so an untouched row cannot carry over prior-row contents.
d Test intent preserved / new tests added? New test 04540_read_wkt_point_empty covers scalar + vectorized POINT EMPTY rejection, case/whitespace variants, valid points still parse, and LINESTRING/POLYGON/MULTIPOLYGON EMPTY remain valid.
e Demonstrated both directions? Pre-fix binary (Build ID 83ce225…) returned garbage/stale coords; fixed binary (fae080f…) rejects with CANNOT_PARSE_TEXT and valid points unchanged. clickhouse-test 04540_read_wkt_point_empty passes with randomization on.
f Fix general, not a narrow patch? Applies to every point-returning path: readWKTPoint (FunctionReadWKT<...CartesianPoint...>) and the readWKT common dispatcher share the same readWKT() helper, gated by the boost point_tag. Non-point empties are intentionally left valid.
g Generalizes across inputs? Empty-point detection is case-insensitive and trims surrounding/interior whitespace (POINT EMPTY, point empty, POINT EMPTY, POINT EMPTY). Already-throwing forms (POINT Z EMPTY, POINT(EMPTY)) are unchanged. MULTIPOINT EMPTY unaffected (it does not reach the point path).
h Backward compatible? Behavior change is limited to input that previously produced undefined/garbage output; no format/setting/default change. SettingsChangesHistory N/A.
i Invariants preserved? The Point block always holds fully-initialized Tuple(Float64,Float64) values; no uninitialized reads. Moving Geometry into the loop removes cross-row state; serializer contract unchanged.

Session id: cron:clickhouse-worker-slot-1:20260716-125100

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @nikitamikhaylov @scanhex12 — review please. Rejects POINT EMPTY in readWKT/readWKTPoint (was returning uninitialized/stale coords), and moves the per-row Geometry inside the loop.

@nikitamikhaylov nikitamikhaylov self-assigned this Jul 16, 2026
@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Jul 16, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [94d69f6]

Summary: ❌

job_name test_name status info comment
Stress test (arm_asan_ubsan, s3) FAIL
Cannot start clickhouse-server FAIL cidb, issue ISSUE CREATED
Logical error: Type mismatch when building statistics for column 'A': statistics expect type B but block has type C (STID: 0250-4148) FAIL cidb IGNORED
Check failed FAIL cidb IGNORED

AI Review

Summary

This PR closes the POINT EMPTY hole in readWKT and readWKTPoint by rejecting unsupported empty points and by reinitializing the typed per-row geometry state so stale coordinates cannot leak across rows. The earlier review thread about leading-whitespace readWKT(' POINT EMPTY ') is fixed in the current code, and I did not find a remaining correctness or compatibility issue in the current diff.

Missing context / blind spots
  • ⚠️ I did not execute the new stateless test locally because this checkout has no build tree; confidence here comes from source inspection and the green Praktika summary rather than a local run.
Final Verdict

✅ No new blockers or majors in the current diff.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jul 16, 2026
Comment thread src/Functions/readWkt.cpp Resolved
FunctionReadWKTCommon::try_deserialize_type dispatched on the untrimmed
lowercased payload, so readWKT(' POINT EMPTY ') matched no type prefix and
fell through to BAD_ARGUMENTS instead of the CANNOT_PARSE_TEXT empty-point
rejection that readWKTPoint already applied. Trim leading whitespace before
the starts_with dispatch so the generic entrypoint rejects the empty point too.

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

Copy link
Copy Markdown
Collaborator Author

Fixed in 56c81f7. FunctionReadWKTCommon::try_deserialize_type now boost::trim_lefts the lowercased payload before the starts_with dispatch, so readWKT(' POINT EMPTY ') reaches the empty-point check and returns CANNOT_PARSE_TEXT instead of BAD_ARGUMENTS. Verified both directions on a debug build (pre-fix: Code 36 BAD_ARGUMENTS; post-fix: Code 6 CANNOT_PARSE_TEXT). Added leading-whitespace and multi-space readWKT(...) assertions to 04540_read_wkt_point_empty.sql; test passes.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 56c81f7

The bot's change request is resolved: FunctionReadWKTCommon::try_deserialize_type now boost::trim_lefts the lowercased payload before the starts_with dispatch (commit 56c81f7), and 04540_read_wkt_point_empty asserts readWKT(' POINT EMPTY ') and readWKT('point empty') both reject with CANNOT_PARSE_TEXT. That test passes across debug/asan/msan/tsan/coverage and the flaky checks.

The remaining red checks are pre-existing trunk issues unrelated to this geometry change (04540 is green everywhere):

Check Reason Owner
Stress test (amd_tsan) Block structure mismatch after liftUpUnion LOGICAL_ERROR on a fuzzed quantilesExactTupleMerge query (STID 0993-23fd); 527 hits / 309 unrelated PRs in 14d incl. master a fix task is created (investigating at full effort; fixing-PR link to follow here)
Stateless tests (amd_llvm_coverage, ..., WasmEdge, 2/3) Server died / Unknown error on the coverage+WasmEdge matrix; 137 unrelated PRs in 7d #109747 (ours, open)
Mergeable Check / PR aggregators reflecting the two lines above (as above)
CH Inc sync private ClickHouse Inc sync CH Inc sync (private, not actionable)

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 56c81f7

Every failure below has an owner: a fixing PR, or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt. None of these failures are caused by this PR's diff (readWkt.cpp POINT EMPTY rejection).

Check / test Reason Owner / fixing PR
Stress test (amd_tsan) — LOGICAL_ERROR "Block structure mismatch ... after optimization liftUpUnion" (STID 0993-23fd) optimizer bug: liftUpUnion produces mismatched block structure for a UNION ALL over quantileExactTupleState merge (fuzzer-generated query) a fix task is moved to pending (investigating at full effort — fixing-PR link to follow here)
Stateless tests (amd_llvm_coverage, old analyzer, s3 storage, DBReplicated, WasmEdge, parallel, 2/3) — "Server died" / "Unknown error" same liftUpUnion LOGICAL_ERROR crashed the server on the coverage build a fix task is moved to pending (same owner as above — fixing-PR link to follow here)
CH Inc sync — CH Inc sync (private, not actionable by us)

Session id: cron:our-pr-ci-monitor:20260716-203000

@groeneai

Copy link
Copy Markdown
Collaborator Author

Fixing PR for the Stress amd_tsan liftUpUnion block-mismatch line (STID 0993-23fd): #110745

…t-point-empty

# Conflicts:
#	src/Functions/readWkt.cpp
@clickhouse-gh

clickhouse-gh Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.20% 86.20% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 78.30% 78.30% +0.00%

Changed lines: Changed C/C++ lines covered: 15/17 (88.24%) · Uncovered code

Full report · Diff report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 94d69f6

Every failure below has an owner. None is caused by this PR's diff (readWKT / readWKTPoint POINT EMPTY rejection + test; this head is a mechanical rebase onto master, functional code byte-identical to the approved 56c81f7).

Check / test Reason Owner / fixing PR
Stress test (arm_asan_ubsan, s3) / statistics type mismatch STID 0250-4148 ("Cannot start clickhouse-server" and "Check failed" are the same crash's restart/summary rows) chronic trunk LOGICAL_ERROR (37 hits / 36 unrelated PRs / 2 master, 30d) a fix task is tracking this at full effort (prior fixing PR #109415 was closed unmerged by the maintainer; fixing-PR link to follow here)
Sync - CH Inc sync (private, not actionable)

Session id: cron:our-pr-ci-monitor:20260721-173000

@nikitamikhaylov
nikitamikhaylov added this pull request to the merge queue Jul 22, 2026
Merged via the queue into ClickHouse:master with commit 33deb04 Jul 22, 2026
177 of 179 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 22, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

Hi @groeneai @nikitamikhaylov — while reviewing this PR I found the following:

Happy to discuss — close anything that's wrong or already addressed.

github-merge-queue Bot pushed a commit that referenced this pull request Jul 26, 2026
readWKTPoint/readWKT('POINT M EMPTY') returned uninitialized coordinates in
the scalar path (garbage subnormal/nan) and silently leaked the previous
row's coordinates in the vectorized path, instead of throwing.

isEmptyPointWKT (added in #110692 to reject bare POINT EMPTY) stripped only
the 'point' prefix and required the remainder to equal exactly 'empty', so
the valid WKT dimension tags Z/M/ZM that may sit between POINT and EMPTY
bypassed the guard. boost::geometry::read_wkt accepts 'POINT M EMPTY' for a
2D point without writing coordinates, so the empty form was not detected.

Strip an optional Z/M/ZM dimension tag (as a whole space-separated token)
before the empty check, so the whole POINT <dim> EMPTY family is rejected
with CANNOT_PARSE_TEXT, matching the existing bare POINT EMPTY handling.
Non-point EMPTY geometries and valid points are unaffected.

Closes: #111505

Co-Authored-By: Claude Opus 4.8 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…kt-point-empty

Reject POINT EMPTY in readWKT / readWKTPoint
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
readWKTPoint/readWKT('POINT M EMPTY') returned uninitialized coordinates in
the scalar path (garbage subnormal/nan) and silently leaked the previous
row's coordinates in the vectorized path, instead of throwing.

isEmptyPointWKT (added in ClickHouse#110692 to reject bare POINT EMPTY) stripped only
the 'point' prefix and required the remainder to equal exactly 'empty', so
the valid WKT dimension tags Z/M/ZM that may sit between POINT and EMPTY
bypassed the guard. boost::geometry::read_wkt accepts 'POINT M EMPTY' for a
2D point without writing coordinates, so the empty form was not detected.

Strip an optional Z/M/ZM dimension tag (as a whole space-separated token)
before the empty check, so the whole POINT <dim> EMPTY family is rejected
with CANNOT_PARSE_TEXT, matching the existing bare POINT EMPTY handling.
Non-point EMPTY geometries and valid points are unaffected.

Closes: ClickHouse#111505

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

readWKT / readWKTPoint expose uninitialized (and stale) memory for POINT EMPTY

5 participants