diff options
author | Damien George <damien.p.george@gmail.com> | 2018-02-19 16:25:30 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2018-02-19 16:25:30 +1100 |
commit | 4e469085c192017c5244bbc115bac90f4bb667cb (patch) | |
tree | d5e1ea8999ef9b179a18432009a4b6bb4549212c /tests/basics/bytes.py | |
parent | 165aab12a3918004325238c794e27e7f4adbb401 (diff) | |
download | micropython-4e469085c192017c5244bbc115bac90f4bb667cb.tar.gz micropython-4e469085c192017c5244bbc115bac90f4bb667cb.zip |
py/objstr: Protect against creating bytes(n) with n negative.
Prior to this patch uPy (on a 32-bit arch) would have severe issues when
calling bytes(-1): such a call would call vstr_init_len(vstr, -1) which
would then +1 on the len and call vstr_init(vstr, 0), which would then
round this up and allocate a small amount of memory for the vstr. The
bytes constructor would then attempt to zero out all this memory, thinking
it had allocated 2^32-1 bytes.
Diffstat (limited to 'tests/basics/bytes.py')
-rw-r--r-- | tests/basics/bytes.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/tests/basics/bytes.py b/tests/basics/bytes.py index 1d97e6b16f..0b6b14fa55 100644 --- a/tests/basics/bytes.py +++ b/tests/basics/bytes.py @@ -56,3 +56,9 @@ print(x[0], x[1], x[2], x[3]) print(bytes([128, 255])) # For sequence of unknown len print(bytes(iter([128, 255]))) + +# Shouldn't be able to make bytes with negative length +try: + bytes(-1) +except ValueError: + print('ValueError') |