Skip to content

Integer overflow is unsafe and release-dependent #109

@hourianto

Description

@hourianto

Unsigned integers are accumulated in uint64 and then cast directly to the target type without range checks. Signed integers rely on conversions that fail as defects in debug builds but become unchecked in release builds because module-wide checks are disabled.

Build with/without -d:release:

import jsony

doAssert "256".fromJson(uint8) == 0'u8
doAssert "999999999999999999999999".fromJson(uint8) == 255'u8

when defined(release):
  doAssert "128".fromJson(int8) == -128'i8
  doAssert "-129".fromJson(int8) == 127'i8
  echo "release signed wraparound reproduced"
else:
  discard "128".fromJson(int8)

Found by GPT 5.4.

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