-
-
Notifications
You must be signed in to change notification settings - Fork 836
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix[codegen]: zero-length dynarray
abi_decode
validation (#4060)
fix an edge case in `abi_decode` dynarray validation. when the child type is dynamic and the runtime length is zero, the check that the offset pointer is valid (points within the payload) was skipped. skipping the offset pointer check is valid any time the runtime length is nonzero, because the pointer is bounded by the checks in the recursive runtime loop in `_dynarray_make_setter`. however, it is invalid to skip the check when the runtime length of the dynarray is zero, because then the recursive loop does not get run. the impact of this can be seen in the included test cases, particularly `test_abi_decode_top_level_head_oob`. although as of eb01136 it is impossible to convince the decoder to *copy* oob data since the validation is only skipped when the length is zero, a payload can be crafted which will revert depending on if some value outside of the buffer is nonzero (i.e. the runtime behavior can be influenced by some data outside of the payload). this commit fixes this issue by _unconditionally_ checking that the offset pointer is valid. note that the check is now always performed, even when the runtime length is nonzero and therefore the check is redundant (because, as stated, the checks within the loop already bound the offset pointer). a more efficient implementation is possible, since the check only needs to be run in the case that the runtime length is 0, which theoretically can be merged into the same basic block with the 0-case in the `repeat` loop. however, this commit leaves that to future optimizer work; the optimization here is it just avoids the multiplication when the child type is dynamic (because the result of the multiplication is always 0). this commit also fixes another bug in dynarray recursion; the calculation in `_abi_payload_size` was not correct when the size of the child type is larger than 32. misc: - add additional tests for abi_decode validation. --------- Co-authored-by: cyberthirst <[email protected]> Co-authored-by: Robert Chen <[email protected]>
- Loading branch information
1 parent
e52241a
commit 1f6b943
Showing
2 changed files
with
259 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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