Skip to content

Account for nanosecond carry and borrow before rejecting Duration overflow #522

Closed

Description

@LunaStev

The checked addition/subtraction functions reject overflow in the seconds component before normalizing nanoseconds. This rejects representable exact results at both ends of the range.

Let MIN/MAX denote the i64 limits and use (seconds, nanoseconds) notation:

  • (MIN, 900000000) + (-1, 200000000) should be (MIN, 100000000).
  • (MAX, 100000000) - (-1, 900000000) should be (MAX, 200000000).

Both currently hit the early error branch. The saturating wrappers consequently return an endpoint instead of these exact results.

Source evidence at the head of #520:

Acceptance:

  • Incorporate carry/borrow into overflow decisions without executing overflowing intermediate signed arithmetic.
  • Cover both examples, reversed addition operands, genuine overflow, and adjacent representable values.
  • Verify the checked and saturating APIs agree whenever the exact normalized result is representable.

Audit status: identified by static source inspection; the scenarios above have not been executed during this audit. The permalink fixes the reviewed revision; this report does not claim the defect was introduced by #520.

Activity

  1. added
    bug
    help wanted
    on Sep 8, 2026
  2. self-assigned this
    on Sep 24, 2026
  3. added a commit that references this issue on Sep 24, 2026
    01955d7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bughelp wanted

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions