Skip to content

[wasm] Int64 marshaling is corrupting data which could not fit JS Number  #69394

@pavelsavara

Description

@pavelsavara

Description

JavaScript Number is float64 type. Integers outside of Number.MAX_SAFE_INTEGER and Number.MIN_SAFE_INTEGER can't be represented.

Out current code from emscripten is

getValue

case 'i64': return HEAP32[((ptr)>>2)];

And setValue

case 'i64': (tempI64 = [value>>>0,(tempDouble=value,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? ((Math.min((+(Math.floor((tempDouble)/4294967296.0))), 4294967295.0))|0)>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)],HEAP32[((ptr)>>2)] = tempI64[0],HEAP32[(((ptr)+(4))>>2)] = tempI64[1]); break;

Reproduction Steps

Net 7.0 preview 4 and below on WASM.

Expected behavior

Use available 52 bits both directions and throw on overflow.
Give user option to marshal also as BigInt

Actual behavior

Value is trimmed to 32bits only.

Regression?

No

Known Workarounds

use double on C# side too.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions