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

Add rudimentary support for decoding Bignum values #2

Merged
merged 1 commit into from
Feb 25, 2021

Conversation

leocassarani
Copy link
Contributor

It turns out that even a simple Unix timestamp is enough to cause Ruby Marshal to output a Bignum. The encoding is reasonably simple: a sign byte (ASCII + or -), half the byte length, then the Bignum's bytes.

Note that as the math/big package requires a big-endian byte encoding, we assume that the input is little-endian and reverse it as needed.

For details, see https://docs.ruby-lang.org/en/master/doc/marshal_rdoc.html#label-Bignum.

It turns out that even a simple Unix timestamp is enough to cause Ruby
Marshal to output a Bignum. The encoding is reasonably simple: a sign
byte (ASCII + or -), half the byte length, then the Bignum's bytes.

Note that as the math/big package requires a big-endian byte encoding,
we assume that the input is little-endian and reverse it as needed.

For details, see https://docs.ruby-lang.org/en/master/doc/marshal_rdoc.html#label-Bignum.
@dozen
Copy link
Owner

dozen commented Feb 25, 2021

@leocassarani thanks! :)

@dozen dozen merged commit c3cae59 into dozen:master Feb 25, 2021
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 this pull request may close these issues.

2 participants