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

Incorrect string to number coercion for '1e1000' #2002

Closed
gorban opened this issue Nov 14, 2024 · 0 comments · Fixed by #2003
Closed

Incorrect string to number coercion for '1e1000' #2002

gorban opened this issue Nov 14, 2024 · 0 comments · Fixed by #2003

Comments

@gorban
Copy link

gorban commented Nov 14, 2024

Version used

Jint 4.1.0 on .NET Framework 4.8

Describe the bug

Browsers and Node.js type coerce the string '1e1000' to the Number Infinity, but Jint gives NaN.

To Reproduce

var engine = new Engine();

// These work
Assert.Equal(double.PositiveInfinity, engine.Evaluate("Number(1e1000)").ToObject());
Assert.Equal(double.PositiveInfinity, engine.Evaluate("+1e1000").ToObject());
Assert.Equal("Infinity", engine.Evaluate("(+1e1000).toString()").ToObject());
Assert.Equal(double.PositiveInfinity, engine.Evaluate("Function('return +' + '1e1000')()").ToObject()); // annoying workaround

// But these fail
Assert.Equal(double.PositiveInfinity, engine.Evaluate("Number('1e1000')").ToObject()); // actually NaN
Assert.Equal(double.PositiveInfinity, engine.Evaluate("+'1e1000'").ToObject()); // actually NaN
Assert.Equal("Infinity", engine.Evaluate("(+'1e1000').toString()").ToObject()); // actually NaN

Expected behavior

  1. (works) +1e1000 --> Infinity (JavaScript) --> double.PositiveInfinity (.NET)
  2. (fails) +'1e1000' --> Infinity (JavaScript) --> double.PositiveInfinity (.NET)

Additional context

Not being able to extract 'y' from Infinity, means you cannot run a JSF*ck transpiler. This is essentially how it gets 'y': (NaN.toString() + (+'1e1000'))[10] and that works in all browsers and Node.js. This is an important language for security research.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant