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

Bug report: 'JSON beautify' operation losing numeric precision #415

Open
n1474335 opened this issue Nov 20, 2018 · 1 comment
Open

Bug report: 'JSON beautify' operation losing numeric precision #415

n1474335 opened this issue Nov 20, 2018 · 1 comment

Comments

@n1474335
Copy link
Member

Summary

When running the 'JSON beautify' operation, numeric precision is lost for large numbers.

Example

https://gchq.github.io/CyberChef/#recipe=JSON_Beautify('%5C%5Ct')&input=eyAiYSI6IDEyMzQ1Njc4OTAxMjM0NTY3ODkgfQ

Input:

{ "a": 1234567890123456789 }

Erroneous output:

{
	"a": 1234567890123456800
}
@PhillipNordwall
Copy link
Contributor

PhillipNordwall commented Nov 21, 2018

Discussion

This issue is arising due to the method of implementing the the beautification library being used.

JSON Spec

The JSON Spec allows implementations to set precision limitations numbers. https://tools.ietf.org/html/rfc7159#section-6.

Implementation

Beautification and minification are done with vkbeautify, which uses Javascript.

Javascript numbers are all represented as a 64 bit float, with a 52 bit mantissa. So the safe range for integer usage is [-2^53,2^53] = [-9007199254740992,9007199254740992]

As the spec allows for this behavior it might be better to classify this as a feature request instead of a bug.

This bug also shows up in 'JSON Minify` as it uses vkbeautify.

'JSON Minify' Example

https://gchq.github.io/CyberChef/#recipe=JSON_Minify()&input=eyAiYSI6IDkwMDcxOTkyNTQ3NDA5OTMgfQ

Input:
{ "a": 9007199254740993 }

Erroneous output:
{"a":9007199254740992}

Other uses of vkbeautify

This library gets used in the following locations. I believe that the JSON ones are the only ones that will have this particular issue as the others are likely not treating the represented numbers as anything other than a string.

  • CSSBeautify.mjs
  • CSSMinify.mjs
  • JSONBeautify.mjs
  • JSONMinify.mjs
  • SQLBeautify.mjs
  • SQLMinify.mjs
  • XMLBeautify.mjs
  • XMLMinify.mjs

BRAVO68WEB pushed a commit to BRAVO68WEB/CyberChef that referenced this issue May 29, 2022
BRAVO68WEB pushed a commit to BRAVO68WEB/CyberChef that referenced this issue May 29, 2022
BRAVO68WEB pushed a commit to BRAVO68WEB/CyberChef that referenced this issue May 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants