You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JSON: UInt64Array encodes unsigned values as signed bits; audit json_encode / json_decode against php #109
Manticore\Ds\UInt64Array (#108) stores unsigned 64-bit values, but PHP has no unsigned int, so an element reads as the int with the same 64 bits: 18446744073709551615 reads as -1. That is the right contract inside a program (bits round-trip through $a[$i] = $a[$j] and fromArray($a->toArray())), but it leaks out of the program through JSON:
$h = newUInt64Array(1);
$h[0] = '18446744073709551615';
echojson_encode($h); // [-1] — a Go / Rust / JS-BigInt consumer reads -1
JSON numbers have no width limit, so the value can be written exactly; today it is written wrong.
JSON as a whole needs a pass beyond this one class: the encoder already had to be taught JsonSerializable (#94) and backed enums (#39) on the Ds branch, and the decoder has its own type gap (#84).
Proposal
UInt64Array::jsonSerialize() emits each element as its unsigned decimal value, unquoted: [18446744073709551615].
Decide and document the decode side: json_decode('[18446744073709551615]') gives a float in php (or a string with JSON_BIGINT_AS_STRING); UInt64Array::fromArray() already accepts both a decimal string and an in-range float, so JSON_BIGINT_AS_STRING is the lossless round trip — say so in docs/ds.md.
Keep toArray(), var_dump(), print_r() and serialize() on bits (the in-program contract).
Audit json_encode / json_decode against php for the remaining flag and type cases (big ints, JSON_PRESERVE_ZERO_FRACTION, JSON_BIGINT_AS_STRING, JSON_THROW_ON_ERROR, depth, invalid UTF-8, objects with non-public properties), filing a repro per difference found.
Out of scope
Changing how $a[$i] reads a UInt64Array element; an arbitrary-precision integer type.
Acceptance criteria
json_encode of a UInt64Array prints every element as its unsigned decimal value; values below 2^63 are unchanged.
json_decode(..., flags: JSON_BIGINT_AS_STRING) + UInt64Array::fromArray() round-trips every value, covered by a case.
docs/ds.md describes the JSON behaviour of UInt64Array.
The JSON audit is done: each php difference found has a repro under tests/aot/repro/ and an issue, or a fix.
Activity