Skip to content

fix(molang): prevent NaN diagnostic ranges from crashing the client#588

Merged
DaanV2 merged 1 commit into
Blockception:mainfrom
DaanV2:claude/serene-ptolemy-qclx6n
Jun 22, 2026
Merged

fix(molang): prevent NaN diagnostic ranges from crashing the client#588
DaanV2 merged 1 commit into
Blockception:mainfrom
DaanV2:claude/serene-ptolemy-qclx6n

Conversation

@DaanV2

@DaanV2 DaanV2 commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

A degenerate molang node (e.g. an empty {} produced by the parser for particle component objects) has an undefined position. The Marker/default case in the molang syntax diagnoser passed that undefined position straight to diagnoser.add, where GetRange resolved it via doc.positionAt(undefined) to a character: NaN. That NaN serializes to null over JSON-RPC, making the client's asDiagnostics reject the entire diagnostic batch with 'Invalid arguments' and drop all diagnostics for the file.

Fixes, in defense-in-depth layers:

  • Guard the degenerate node's position with a finite fallback in the molang syntax diagnoser.
  • Clamp non-finite/out-of-bounds offsets to the document bounds in GetRange and GetPosition so no caller can produce a NaN range.

Adds regression tests for both layers.

A degenerate molang node (e.g. an empty `{}` produced by the parser for
particle component objects) has an undefined `position`. The Marker/default
case in the molang syntax diagnoser passed that undefined position straight
to `diagnoser.add`, where `GetRange` resolved it via `doc.positionAt(undefined)`
to a `character: NaN`. That NaN serializes to `null` over JSON-RPC, making the
client's `asDiagnostics` reject the entire diagnostic batch with 'Invalid
arguments' and drop all diagnostics for the file.

Fixes, in defense-in-depth layers:
- Guard the degenerate node's position with a finite fallback in the molang
  syntax diagnoser.
- Clamp non-finite/out-of-bounds offsets to the document bounds in GetRange
  and GetPosition so no caller can produce a NaN range.

Adds regression tests for both layers.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HGuhKH5dAiLG2f19DJ39T7
@DaanV2 DaanV2 merged commit 88abe99 into Blockception:main Jun 22, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants