Skip to content

Reject NaN/Infinity in JS arguments to avoid silent conversion #93

@bbopen

Description

@bbopen

Summary

JSON.stringify silently converts NaN, Infinity, and -Infinity to null in arrays/objects. This causes silent data corruption when passing numeric arguments into the bridge.

Failure mode

  • Call bridge.call('math', 'sqrt', [NaN]).
  • Payload JSON contains null instead of NaN.
  • Python receives None and executes with unexpected values.

Evidence

  • src/runtime/node.ts send() uses JSON.stringify(message) directly.
  • JSON.stringify converts non-finite numbers to null.

Proposed fix

  • Validate arguments/kwargs for non-finite numbers before serialization and throw a clear BridgeProtocolError.
  • Optionally add a strict mode that rejects unsupported JS types (functions, symbols, undefined).

Acceptance criteria

  • Passing NaN/Infinity in args or kwargs throws a clear error and does not silently convert.
  • Add tests covering NaN/Infinity in both args and kwargs.

Metadata

Metadata

Assignees

Labels

area:runtime-nodeArea: Node runtime bridgebugSomething isn't workingpriority:p2Priority P2 (medium)

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions