Skip to content

NaN in @indexed Float sorts positive → leaks into > N range queries (silent-wrong); search_by_value(NaN) → 500 #1436

Open

Description

@kriszyp

Summary

IEEE-754 NaN is mishandled by the @indexed Float path. NaN's stored bit pattern sorts into the positive region of the ordered index, so it leaks into > 0 / > N range-query results (silent wrong results — IEEE-754 mandates every ordered comparison with NaN is false, so NaN must never appear in a range result). Separately, search_by_value(val = NaN) crashes with a 500.

Severity: Medium — silent wrong results in range queries. Reachability is narrow: NaN/±Infinity are not representable in JSON, so they can only enter via CBOR (application/cbor) or msgpack write paths — real for sensor/scientific apps where a computed reading can be 0/0, log(-x), overflow→Inf, etc.

Symptoms

Range-query leak (the real concern): search_by_conditions(val > 0) and (val > N) on an @indexed Float column return rows whose value is NaN. val < 0 correctly excludes NaN — confirming this is a sort-position bug (NaN's canonical encoding is a large positive integer under raw bit-reinterpretation), not random.

Crash: search_by_value(val = NaN) → HTTP 500, TypeError: Cannot read properties of null (reading 'includes') at dist/dataLayer/harperBridge/ResourceBridge.js:393. Returning [] would be the correct IEEE outcome; crashing is not.

Sort-position inconsistency: REST ?sort(fval) ASC puts NaN last, DESC puts NaN first; SQL ORDER BY fval puts NaN between 0 and 1.0. No position is IEEE-correct (NaN is unordered) and REST and SQL disagree → silent-wrong for any sort-dependent query. Finite ordering (-∞ < -1 < +1 < +∞) is correct on both.

GROUP BY merges NaN with NULL: SQL GROUP BY fval yields {fval: null, cnt: 1} for the NaN row — NaN coerced to the null group key, no separate NaN group. A WHERE fval IS NULL query would then pick up the NaN row (identity confusion).

Contained (good — no structural corruption)

CBOR re-encode round-trip (GET → re-PUT → GET) preserves NaN; neighbor-index integrity holds — a NaN DELETE fully cleans the index, and > 0 / < 0 / = 1.0 all return correct non-NaN neighbors afterward (no wedge), both engines identical. The index structure is not corrupted — the defect is NaN's bad sort-position + NULL-merge, not a broader integrity failure.

Not bugs (defensible companions)

JSON Accept emits null for NaN/±Inf (only spec-valid choice); -0 stored as +0; SQL MIN/MAX→null and AVG/SUM→{} when a NaN/Inf is in the column (the finite-only subset aggregates correctly).

Suggested fix

Normalize NaN to sort consistently (or exclude it from ordered-index range results), and guard the search_by_value NaN path to return [] (or a clean 4xx) instead of 500. One fix to the index ordering + a search-value guard addresses the whole cluster (range-leak, crash, sort-position, GROUP-BY-NULL-merge), which all flow from "NaN has no consistent sort position and isn't special-cased."

Note when reproducing: drive it via the search_by_value(val=NaN) op + search_by_conditions(val > 0) specifically (REST FIQL ?fv=NaN correctly returns 400 and does not hit this path).


Found via exploratory QA (scenarios QA-207 / QA-209) against 7aaa5a152 on a feature branch; expected to reproduce on main. Filed by Claude (Opus 4.8) on Kris's go-ahead.

Activity

  1. added this to the v5.3 milestone on Aug 7, 2026
  2. added theissue type on Aug 7, 2026
  3. modified the milestones: v5.3, v5.4 on Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    Priority

    P2

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions