Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
pavelsavara opened this issue May 16, 2022 · 1 comment · Fixed by #66304
Closed

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

pavelsavara opened this issue May 16, 2022 · 1 comment · Fixed by #66304
Assignees
Milestone

Comments

@pavelsavara
Copy link
Member

pavelsavara commented May 16, 2022

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.

@pavelsavara pavelsavara self-assigned this May 16, 2022
@ghost ghost added the untriaged New issue has not been triaged by the area owner label May 16, 2022
@ghost
Copy link

ghost commented May 16, 2022

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

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.

Actual behavior

Value is trimmed to 32bits only.

Regression?

No

Known Workarounds

use double on C# side too.

Configuration

No response

Other information

No response

Author: pavelsavara
Assignees: pavelsavara
Labels:

arch-wasm, area-System.Runtime.InteropServices.JavaScript

Milestone: -

@pavelsavara pavelsavara removed the untriaged New issue has not been triaged by the area owner label May 16, 2022
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jun 6, 2022
@jeffhandley jeffhandley added this to the 7.0.0 milestone Jun 25, 2022
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jul 10, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Aug 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants