Repository navigation
fix(vector): reject NaN/Inf vector elements at the cast boundary (#28688) - #28881
Conversation
…rixorigin#28688) Non-finite vector components (NaN/±Inf) poisoned IVFFLAT build: a non-finite probe makes every centroid distance non-finite, the nearest-centroid argmin never advances past its -1 sentinel, and productl2 fed -1 into Vector.UnionOne -> "index out of range [-8]" panic, returning a Go stack to the client. kmeans centroid means were equally exposed. Fix at the write boundary: stringToT rejects NaN/±Inf after parsing each float element, so non-finite values never reach storage or any index (kmeans, argmin, top-k heap, usearch, cuVS). Covers INSERT, UPDATE, LOAD DATA (CSV), and parquet plain-string, since all funnel through StringToArray -> stringToT. Integer narrow vectors (vecint8/vecuint8) cannot be non-finite and are untouched. For BF16/Float16 the check runs on the NARROWED value: a finite literal can overflow the 16-bit range to ±Inf during narrowing (e.g. 70000 -> f16 +Inf, 3.4e38 -> bf16 +Inf), which the pre-narrowing check would miss. Tests: unit tests for NaN/±Inf across all float types plus the narrow-overflow case; BVT array_nonfinite.sql covers INSERT/UPDATE/LOAD DATA rejection for vecf32/f64/bf16/f16 and confirms IVFFLAT builds on the surviving finite rows. Note: rejecting at the shared parse boundary also rejects re-parsing of pre-existing non-finite vectors (export->reimport / restore of data written before this fix). Non-finite vectors are data errors with no valid use; handling already-stored non-finite data (index-build/heap/kmeans hardening) is a separate follow-up. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
GPT-6 medium deep review at head c00b64b. The cast-boundary checks reject NaN/Inf for float vectors and validate values after narrowing for BF16/F16, while preserving integer-vector behavior. I found no introduced correctness blocker. The exact-head CI is green; this change adds no new racing UT whose individual runtime exceeds the 45.55s limit.
Merge Queue Status
This pull request spent 53 minutes 21 seconds in the queue, including 53 minutes 3 seconds running CI. Required conditions to merge
|
XuPeng-SH
left a comment
There was a problem hiding this comment.
GPT-6 medium deep review at exact head f6b0e7b. The PR's effective diff is unchanged from the reviewed vector cast-boundary change; the new head only syncs main. It rejects NaN/Inf for float vectors and validates after narrowing for BF16/F16, while leaving integer-vector behavior unchanged. I found no introduced correctness blocker. CI has restarted on this synchronized head and is still in progress; this approval records the code review, not a claim that the new run has completed.
…rixorigin#28688) (matrixorigin#28881) Fixes matrixorigin#28688 — creating an IVFFLAT index on a column that contains a `NaN` or `±Inf` vector component panicked with a Go runtime stack returned to the client: internal error: panic runtime error: index out of range [-8]: vector.(*Vector).UnionOne productl2.probeRun[...] Affected every float vector type IVFFLAT supports (`vecf32`, `vecf64`, `vecf16`, `vecbf16`); integer narrow vectors are not affected. ## Root cause A non-finite probe makes **every** centroid distance non-finite (`NaN - x = NaN`, `Inf² = +Inf`), and the distance functions propagate that silently (no guard). In the `limit==1` nearest-centroid assignment the argmin seeds `minIdx = -1` / `minDist = MaxFloat` and only advances on `dist < minDist` — but `NaN < x` and `+Inf < MaxFloat` are both false, so `minIdx` stays `-1`. `productl2` then calls `Vector.UnionOne(src, -1)` → byte offset `-1 × 8 = -8` → panic. kmeans centroid means were equally exposed (a non-finite training row makes the mean non-finite, poisoning all subsequent distances). ## Fix Reject `NaN`/`±Inf` vector components at the **cast boundary** — `pkg/container/types/array_str.go`, in `stringToT` after each `strconv.ParseFloat`: - New `rejectNonFiniteArrayElem(num)` returns an error on `NaN`/`±Inf`. - `float32`/`float64`: checked on the parsed value (matched-bitSize `ParseFloat` already errors on overflow). - `BF16`/`Float16`: checked on the **narrowed** value — a finite literal can overflow the 16-bit range to `±Inf` during narrowing (`70000` → f16 `+Inf`, `3.4e38` → bf16 `+Inf`), which a pre-narrowing check would miss. - `int8`/`uint8` untouched (integers cannot be non-finite). Because every write path funnels through `StringToArray → stringToT`, this single check covers **INSERT, UPDATE, LOAD DATA (CSV), and parquet plain-string import** — so no non-finite value ever reaches storage or any index (kmeans, argmin, top-k heap, usearch, cuVS). Errors surface cleanly as `internal error: vector element cannot be NaN or Inf: <value>` instead of a runtime panic. ## Testing - **Unit** (`array_str_test.go`): `NaN`/`+Inf`/`-Inf` (incl. lowercase) rejected across `float32/float64/BF16/Float16`; finite values and `int8/uint8` parse normally; the narrow-type overflow case (`70000`→f16, `3.4e38`→bf16) is rejected while in-range narrow values still parse. - **BVT** (`cases/array/array_nonfinite.sql`): INSERT / UPDATE / LOAD DATA reject non-finite for `vecf32/f64/bf16/f16`; a finite LOAD control loads normally; `CREATE INDEX … USING ivfflat` builds on the surviving finite rows (the issue's exact scenario). mo-tester run mode **45/45 (100%)**. - Validated live on a two-CN cluster: the issue's repro now errors at INSERT instead of panicking at CREATE INDEX. Approved by: @XuPeng-SH
…rixorigin#28688) (matrixorigin#28881) Fixes matrixorigin#28688 — creating an IVFFLAT index on a column that contains a `NaN` or `±Inf` vector component panicked with a Go runtime stack returned to the client: internal error: panic runtime error: index out of range [-8]: vector.(*Vector).UnionOne productl2.probeRun[...] Affected every float vector type IVFFLAT supports (`vecf32`, `vecf64`, `vecf16`, `vecbf16`); integer narrow vectors are not affected. ## Root cause A non-finite probe makes **every** centroid distance non-finite (`NaN - x = NaN`, `Inf² = +Inf`), and the distance functions propagate that silently (no guard). In the `limit==1` nearest-centroid assignment the argmin seeds `minIdx = -1` / `minDist = MaxFloat` and only advances on `dist < minDist` — but `NaN < x` and `+Inf < MaxFloat` are both false, so `minIdx` stays `-1`. `productl2` then calls `Vector.UnionOne(src, -1)` → byte offset `-1 × 8 = -8` → panic. kmeans centroid means were equally exposed (a non-finite training row makes the mean non-finite, poisoning all subsequent distances). ## Fix Reject `NaN`/`±Inf` vector components at the **cast boundary** — `pkg/container/types/array_str.go`, in `stringToT` after each `strconv.ParseFloat`: - New `rejectNonFiniteArrayElem(num)` returns an error on `NaN`/`±Inf`. - `float32`/`float64`: checked on the parsed value (matched-bitSize `ParseFloat` already errors on overflow). - `BF16`/`Float16`: checked on the **narrowed** value — a finite literal can overflow the 16-bit range to `±Inf` during narrowing (`70000` → f16 `+Inf`, `3.4e38` → bf16 `+Inf`), which a pre-narrowing check would miss. - `int8`/`uint8` untouched (integers cannot be non-finite). Because every write path funnels through `StringToArray → stringToT`, this single check covers **INSERT, UPDATE, LOAD DATA (CSV), and parquet plain-string import** — so no non-finite value ever reaches storage or any index (kmeans, argmin, top-k heap, usearch, cuVS). Errors surface cleanly as `internal error: vector element cannot be NaN or Inf: <value>` instead of a runtime panic. ## Testing - **Unit** (`array_str_test.go`): `NaN`/`+Inf`/`-Inf` (incl. lowercase) rejected across `float32/float64/BF16/Float16`; finite values and `int8/uint8` parse normally; the narrow-type overflow case (`70000`→f16, `3.4e38`→bf16) is rejected while in-range narrow values still parse. - **BVT** (`cases/array/array_nonfinite.sql`): INSERT / UPDATE / LOAD DATA reject non-finite for `vecf32/f64/bf16/f16`; a finite LOAD control loads normally; `CREATE INDEX … USING ivfflat` builds on the surviving finite rows (the issue's exact scenario). mo-tester run mode **45/45 (100%)**. - Validated live on a two-CN cluster: the issue's repro now errors at INSERT instead of panicking at CREATE INDEX. Approved by: @XuPeng-SH
…rixorigin#28688) (matrixorigin#28881) Fixes matrixorigin#28688 — creating an IVFFLAT index on a column that contains a `NaN` or `±Inf` vector component panicked with a Go runtime stack returned to the client: internal error: panic runtime error: index out of range [-8]: vector.(*Vector).UnionOne productl2.probeRun[...] Affected every float vector type IVFFLAT supports (`vecf32`, `vecf64`, `vecf16`, `vecbf16`); integer narrow vectors are not affected. ## Root cause A non-finite probe makes **every** centroid distance non-finite (`NaN - x = NaN`, `Inf² = +Inf`), and the distance functions propagate that silently (no guard). In the `limit==1` nearest-centroid assignment the argmin seeds `minIdx = -1` / `minDist = MaxFloat` and only advances on `dist < minDist` — but `NaN < x` and `+Inf < MaxFloat` are both false, so `minIdx` stays `-1`. `productl2` then calls `Vector.UnionOne(src, -1)` → byte offset `-1 × 8 = -8` → panic. kmeans centroid means were equally exposed (a non-finite training row makes the mean non-finite, poisoning all subsequent distances). ## Fix Reject `NaN`/`±Inf` vector components at the **cast boundary** — `pkg/container/types/array_str.go`, in `stringToT` after each `strconv.ParseFloat`: - New `rejectNonFiniteArrayElem(num)` returns an error on `NaN`/`±Inf`. - `float32`/`float64`: checked on the parsed value (matched-bitSize `ParseFloat` already errors on overflow). - `BF16`/`Float16`: checked on the **narrowed** value — a finite literal can overflow the 16-bit range to `±Inf` during narrowing (`70000` → f16 `+Inf`, `3.4e38` → bf16 `+Inf`), which a pre-narrowing check would miss. - `int8`/`uint8` untouched (integers cannot be non-finite). Because every write path funnels through `StringToArray → stringToT`, this single check covers **INSERT, UPDATE, LOAD DATA (CSV), and parquet plain-string import** — so no non-finite value ever reaches storage or any index (kmeans, argmin, top-k heap, usearch, cuVS). Errors surface cleanly as `internal error: vector element cannot be NaN or Inf: <value>` instead of a runtime panic. ## Testing - **Unit** (`array_str_test.go`): `NaN`/`+Inf`/`-Inf` (incl. lowercase) rejected across `float32/float64/BF16/Float16`; finite values and `int8/uint8` parse normally; the narrow-type overflow case (`70000`→f16, `3.4e38`→bf16) is rejected while in-range narrow values still parse. - **BVT** (`cases/array/array_nonfinite.sql`): INSERT / UPDATE / LOAD DATA reject non-finite for `vecf32/f64/bf16/f16`; a finite LOAD control loads normally; `CREATE INDEX … USING ivfflat` builds on the surviving finite rows (the issue's exact scenario). mo-tester run mode **45/45 (100%)**. - Validated live on a two-CN cluster: the issue's repro now errors at INSERT instead of panicking at CREATE INDEX. Approved by: @XuPeng-SH
What type of PR is this?
Which issue(s) this PR fixes:
issue #28688
What this PR does / why we need it:
Fixes #28688 — creating an IVFFLAT index on a column that contains a
NaNor±Infvector component panicked with a Goruntime stack returned to the client:
internal error: panic runtime error: index out of range [-8]:
vector.(*Vector).UnionOne
productl2.probeRun[...]
Affected every float vector type IVFFLAT supports (
vecf32,vecf64,vecf16,vecbf16); integer narrow vectors are notaffected.
Root cause
A non-finite probe makes every centroid distance non-finite (
NaN - x = NaN,Inf² = +Inf), and the distance functionspropagate that silently (no guard). In the
limit==1nearest-centroid assignment the argmin seedsminIdx = -1/minDist = MaxFloatand only advances ondist < minDist— butNaN < xand+Inf < MaxFloatare both false, sominIdxstays-1.productl2then callsVector.UnionOne(src, -1)→ byte offset-1 × 8 = -8→ panic. kmeans centroid means were equallyexposed (a non-finite training row makes the mean non-finite, poisoning all subsequent distances).
Fix
Reject
NaN/±Infvector components at the cast boundary —pkg/container/types/array_str.go, instringToTafter eachstrconv.ParseFloat:rejectNonFiniteArrayElem(num)returns an error onNaN/±Inf.float32/float64: checked on the parsed value (matched-bitSizeParseFloatalready errors on overflow).BF16/Float16: checked on the narrowed value — a finite literal can overflow the 16-bit range to±Infduringnarrowing (
70000→ f16+Inf,3.4e38→ bf16+Inf), which a pre-narrowing check would miss.int8/uint8untouched (integers cannot be non-finite).Because every write path funnels through
StringToArray → stringToT, this single check covers INSERT, UPDATE, LOAD DATA(CSV), and parquet plain-string import — so no non-finite value ever reaches storage or any index (kmeans, argmin, top-k
heap, usearch, cuVS). Errors surface cleanly as
internal error: vector element cannot be NaN or Inf: <value>instead of aruntime panic.
Testing
array_str_test.go):NaN/+Inf/-Inf(incl. lowercase) rejected acrossfloat32/float64/BF16/Float16; finitevalues and
int8/uint8parse normally; the narrow-type overflow case (70000→f16,3.4e38→bf16) is rejected while in-rangenarrow values still parse.
cases/array/array_nonfinite.sql): INSERT / UPDATE / LOAD DATA reject non-finite forvecf32/f64/bf16/f16; afinite LOAD control loads normally;
CREATE INDEX … USING ivfflatbuilds on the surviving finite rows (the issue's exactscenario). mo-tester run mode 45/45 (100%).