Skip to content

CLI numeric parsing accepts unsafe integers and silently changes values #3

@aeitwoen

Description

@aeitwoen

Problem

While integrating the CLI in automation, I noticed numeric args are validated with /^\\d+$/ and then converted using Number(...) in src/commands/_db.ts and src/commands/observation.ts. That accepts values larger than Number.MAX_SAFE_INTEGER and silently rounds them.

Example:

node -e "console.log(Number('9007199254740993'))"
# -> 9007199254740992

parseId("9007199254740993") currently returns a different value than what the user passed.

Why this matters

SQLite IDs are 64-bit integers. The CLI currently lets users pass a value that cannot be represented safely in JS, which can target the wrong record in large datasets.

Affected paths

  • src/commands/_db.ts (parseId)
  • src/commands/observation.ts (parseOptionalInt)
  • Any command using those helpers

Suggested fix

  • Reject numeric strings above Number.MAX_SAFE_INTEGER
  • Use Number.isSafeInteger(parsed) after parsing
  • Return a clear error when value is out of safe range

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions