Repository navigation
Check integer ranges and BytesN lengths in ContractSpec - #199
Merged
Merged
Conversation
Fixes a defect in `ContractSpec` argument conversion. Before this change, `nativeToXdrSCVal` checked a `u32` integer only for a negative sign and an `i32` integer not at all. The XDR encoder kept the low 32 bits of the value, so a `u32` of 4294967296 encoded as 0 and an `i32` of 2147483648 as -2147483648 without an error. A `BytesN` parameter took a string of any length and produced an `SCVal` that the host rejects. An app that passed a user-supplied integer to a contract function could therefore invoke it with a wrong value. A byte string of the wrong length failed at the host. This change: - Rejects a `u32` or `i32` integer outside its range with an `InvalidArgumentException` naming the value and the range. - Checks the byte length of a `BytesN` string against the declared length and rejects a mismatch with an `InvalidArgumentException` naming both lengths. - Adds boundary tests for the two integer types and for `BytesN` of lengths 0 and 32 with binary and multibyte strings, and names the three rules in the function's documentation. - Moves the TxRep entry of the CHANGELOG from the 1.17.0 section to Unreleased. Every value inside its type and every string of the declared length converts to the same `SCVal` as before. Closes #198
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #199 +/- ##
=========================================
Coverage 93.46% 93.46%
- Complexity 21603 21609 +6
=========================================
Files 1006 1006
Lines 52392 52399 +7
=========================================
+ Hits 48967 48974 +7
Misses 3425 3425
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes a defect in
ContractSpecargument conversion. Before this change,nativeToXdrSCValchecked au32integer only for a negative sign and ani32integer not at all. The XDR encoder kept the low 32 bits of the value, so au32of 4294967296 encoded as 0 and ani32of 2147483648 as -2147483648 without an error. ABytesNparameter took a string of any length and produced anSCValthat the host rejects. An app that passed a user-supplied integer to a contract function could therefore invoke it with a wrong value. A byte string of the wrong length failed at the host.This change:
u32ori32integer outside its range with anInvalidArgumentExceptionnaming the value and the range.BytesNstring against the declared length and rejects a mismatch with anInvalidArgumentExceptionnaming both lengths.BytesNof lengths 0 and 32 with binary and multibyte strings, and names the three rules in the function's documentation.Every value inside its type and every string of the declared length converts to the same
SCValas before.Closes #198