-
Notifications
You must be signed in to change notification settings - Fork 146
feat(scale): add range checks to decodeUint function #2683
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
Changes from all commits
ceb073c
1ea546d
3c79993
ea5836a
a289ece
8b77f71
9f53087
9787bd3
6a542d4
6494fe2
f11c61b
3d5f687
8ae1960
dd4c99a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -176,6 +176,11 @@ var ( | |
| in: int(1), | ||
| want: []byte{0x04}, | ||
| }, | ||
| { | ||
| name: "int(42)", | ||
| in: int(42), | ||
| want: []byte{0xa8}, | ||
| }, | ||
| { | ||
| name: "int(16383)", | ||
| in: int(16383), | ||
|
|
@@ -820,9 +825,11 @@ var ( | |
| want: []byte{0x10, 0x03, 0x00, 0x00, 0x00, 0x40, 0x08, 0x0c, 0x10}, | ||
| }, | ||
| { | ||
| name: "[]int{1 << 32, 2, 3, 1 << 32}", | ||
| in: []int{1 << 32, 2, 3, 1 << 32}, | ||
| want: []byte{0x10, 0x07, 0x00, 0x00, 0x00, 0x00, 0x01, 0x08, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00, 0x01}, | ||
| name: "[]int64{1 << 32, 2, 3, 1 << 32}", | ||
| in: []int64{1 << 32, 2, 3, 1 << 32}, | ||
| want: []byte{0x10, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, | ||
| 0x00}, | ||
|
Comment on lines
+828
to
+832
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: this was changed because after refactoring Returns error: While our code ignores remaining bytes on buffer. Let me know any ideas how to check if bytes remain. Correct encoding determined by parity scale codec:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we use the same function for a target Looking at the test code in decode_all.rs, for struct types you need to handle each attribute specifically when implementing the I tried adding a test with the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes sense, thanks. |
||
| }, | ||
| { | ||
| name: "[]bool{true, false, true}", | ||
|
|
@@ -863,9 +870,11 @@ var ( | |
| want: []byte{0x03, 0x00, 0x00, 0x00, 0x40, 0x08, 0x0c, 0x10}, | ||
| }, | ||
| { | ||
| name: "[4]int{1 << 32, 2, 3, 1 << 32}", | ||
| in: [4]int{1 << 32, 2, 3, 1 << 32}, | ||
| want: []byte{0x07, 0x00, 0x00, 0x00, 0x00, 0x01, 0x08, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00, 0x01}, | ||
| name: "[4]int64{1 << 32, 2, 3, 1 << 32}", | ||
| in: [4]int64{1 << 32, 2, 3, 1 << 32}, | ||
| want: []byte{0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, | ||
| 0x00}, | ||
|
Comment on lines
+873
to
+877
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: this was changed because after refactoring decodeUint it was getting errors, which is consistent with parity scale codec behavior, confirm when testing with: #[test]
fn decode_vec() {
let encoded = vec![0x07, 0x00, 0x00, 0x00, 0x00, 0x01, 0x08, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00, 0x01];
let result = <Vec<u8>>::decode_all(&mut encoded.as_slice());
println!("result: {:?}", result);
} |
||
| }, | ||
| { | ||
| name: "[3]bool{true, false, true}", | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.