Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
feat(scale): add range checks to decodeUint function #2683
feat(scale): add range checks to decodeUint function #2683
Changes from 12 commits
ceb073c
1ea546d
3c79993
ea5836a
a289ece
8b77f71
9f53087
9787bd3
6a542d4
6494fe2
f11c61b
3d5f687
8ae1960
dd4c99a
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Note: this was changed because after refactoring
decodeUint
it was getting errors, which is consistent with parity scale codec behavior, confirm when testing with:Returns error:
Err(Error { cause: None, desc: "Input buffer has still data left after decoding!" })
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:
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.
Since we use the same function for a target
uint
in astruct
, and to auint
directly, it will be difficult to error out correctly without refactoring things significantly. I was trying to figure out how substrate deals with this, but I kinda got lost navigating around. I would assume this error only comes as a result of usingdecode_all
, which implies that all the bytes should be read.Looking at the test code in decode_all.rs, for struct types you need to handle each attribute specifically when implementing the
Decode
trait. This differs from our scale package, since it decodes optimistically across the struct attributes.I tried adding a test with the
Vec<u8>
as an attribute, and I passed in the bytes that produced that error usingdecode_all
and It didn't produce that error when it's a struct attribute. SeeTestStruct2
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.
This makes sense, thanks.
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.
Note: this was changed because after refactoring decodeUint it was getting errors, which is consistent with parity scale codec behavior, confirm when testing with: