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

IDs don't seem to be parsed properly when received as numbers? #696

Closed
minhducsun2002 opened this issue Mar 20, 2022 · 2 comments
Closed
Labels
Bug Something isn't working Module: API
Milestone

Comments

@minhducsun2002
Copy link
Contributor

I'm having issues replying to messages. My message object contains something like this on the sending side :

"message_reference": {
	"message_id":954979821636042816,
	"channel_id":954027702603522075,
	"guild_id":954027701865324570,
	"fail_if_not_exists":false
}

However, the server gets it (I inserted a console.log @ https://github.com/fosscord/fosscord-server/blob/master/api/src/util/handlers/Message.ts#L85) as

{
  message_id: '954979821636042800',
  channel_id: '954027702603522000',
  guild_id: '954027701865324500',
  fail_if_not_exists: false
}

The 00 suffixes on the received data signalled to me that there seems to be truncation happening due to the numbers stepping outside of JavaScript's safe limit on integers (Number.MAX_SAFE_INTEGER). Discord works fine with this however.

@erkinalp erkinalp added Bug Something isn't working Module: API labels Mar 20, 2022
@erkinalp erkinalp added this to the Discord Core milestone Mar 20, 2022
@Intevel Intevel removed their assignment Mar 27, 2022
@MaddyUnderStars
Copy link
Member

This bug is due to how body-parser uses JSON.parse, which uses Number types instead of BigInt or string for large numbers. A similar fix was already done with the gateway ( swapping our usage of JSON.parse with the json-bitint npm package ), but for body-parser we'd have to patch the library. I've done a bit of local testing and it seems fine, but patching such an important package is a bit awkward. Maybe conditionally use json-bitint?

@MaddyUnderStars
Copy link
Member

Addressed in #309 and 22346c4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Module: API
Projects
None yet
Development

No branches or pull requests

4 participants