Skip to content
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[codegen]: overflow check in slice() #3818

Merged
merged 12 commits into from
Mar 21, 2024
13 changes: 11 additions & 2 deletions vyper/builtins/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,19 @@ def build_IR(self, expr, args, kwargs, context):

do_copy = copy_bytes(copy_dst, copy_src, copy_len, copy_maxlen)

# make sure we don't overrun the source buffer, checking for
# overflow:
# `assert start+length <= src_len && start+length <= length`
bounds_check = [
"with",
"end",
["add", start, length],
["assert", ["iszero", ["or", ["gt", "end", src_len], ["gt", "end", length]]]],
]

ret = [
"seq",
# make sure we don't overrun the source buffer
["assert", ["le", ["add", start, length], src_len]], # bounds check
bounds_check,
do_copy,
["mstore", dst, length], # set length
dst, # return pointer to dst
Expand Down
Loading