-
Notifications
You must be signed in to change notification settings - Fork 96
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
fix: Cbor.encode(BigInt(n)) possible failure #624
base: main
Are you sure you want to change the base?
Conversation
Dear @neeboo, In order to potentially merge your code in this open-source repository and therefore proceed with your contribution, we need to have your approval on DFINITY's CLA1. If you decide to agree with it, please visit this issue and read the instructions there. — The DFINITY Foundation Footnotes
|
Dear @neeboo, In order to potentially merge your code in this open-source repository and therefore proceed with your contribution, we need to have your approval on DFINITY's CLA1. If you decide to agree with it, please visit this issue and read the instructions there. — The DFINITY Foundation Footnotes
|
Cbor.encode(BigInt(n))
possible failureCbor.encode(BigInt(n))
possible failure
Co-authored-by: Kyle Peacock <kylpeacock@gmail.com>
Cbor.encode(BigInt(n))
possible failure@@ -27,6 +27,12 @@ const hexRe = new RegExp(/^([0-9A-F]{2})*$/i); | |||
* @param hex The hexadecimal string to use. | |||
*/ | |||
export function fromHex(hex: string): ArrayBuffer { | |||
//FIXME: always padding hex string length to be even |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the rationale for this? Does decoding break for odd-length hex strings?
} | ||
// // if we log the time | ||
// if (i % 100000 === 0) { | ||
// console.log(`${new Date(Date.now()).toLocaleTimeString()} with ${i.toString()}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason these comments are left in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can delete those
When serializing objects that contain
Has some progress been made on this? |
Fix
Cbor.encode(BigInt(n))
possible failureDescription
When use
Cbor.encode
, if passed value is BigInt, first will run the BigInt encoder and transform BigInt value to be a hex string. However thisBigInt(n).toString(16)
would probrably generate a hex string length not to be even, which won't pass the RegTest in thefromHex
function.Fixes # (issue)
Added a zero-padding while passing hex string length is not even.
How Has This Been Tested?
test cases are in
cbor.tests.ts
Checklist: