Skip to content

Native PHIR-JSON engine loses negative and >32-bit ffcall return values #1332

Open

Description

@ciaranra

The native PHIR-JSON engine loses foreign-call (ffcall) return values that are negative or wider than 32 bits.

Cause (from source on the #1314 branch; same on dev)

In crates/pecos-phir-json/src/v0_1/operations.rs (~1311, ~1324, ~1384, ~1396), ffcall results are converted with u32::try_from(result[i]).unwrap_or(0) (and similar). A negative return value, or one above u32::MAX, silently becomes 0 before it is stored. Some whole-result paths use u64::try_from(...).unwrap_or(0), which turns negative returns into 0 as well.

The default Rust interpreter and the Python interpreter keep the two's-complement value, so the same program gives different results depending on the PHIR path.

Direction

Convert ffcall returns into the destination register's type with the PHIR spec's integer semantics (variables behave as i64, then wrap to the declared width), the same way = assignment does, with no unwrap_or(0). If a value cannot be represented, report an error naming the call, the value and the destination. Add tests with negative and >32-bit returns on the native engine and both interpreters.

Found during the review of the #1314 work.

Activity

  1. added
    bugSomething isn't working
    rustPull requests that update rust code
    severity:highBroken functionality or loud failure in a supported path
    severity:criticalSilently wrong results, data loss, or security exposure
    and removed
    severity:highBroken functionality or loud failure in a supported path
    on Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingrustPull requests that update rust codeseverity:criticalSilently wrong results, data loss, or security exposure

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions