mirror of
https://github.com/micropython/micropython.git
synced 2026-01-07 04:30:24 +01:00
py/binary: Change internal bytearray typecode from 0 to 1.
The value of 0 can't be used because otherwise mp_binary_get_size will let a null byte through as the type code (intepreted as byterray). This can lead to invalid type-specifier strings being let through without an error in the struct module, and even buffer overruns.
This commit is contained in:
@@ -40,3 +40,30 @@ try:
|
||||
struct.calcsize('0z')
|
||||
except:
|
||||
print('Exception')
|
||||
|
||||
# check that a count without a type specifier raises an exception
|
||||
|
||||
try:
|
||||
struct.calcsize('1')
|
||||
except:
|
||||
print('Exception')
|
||||
|
||||
try:
|
||||
struct.pack('1')
|
||||
except:
|
||||
print('Exception')
|
||||
|
||||
try:
|
||||
struct.pack_into('1', bytearray(4), 0, 'xx')
|
||||
except:
|
||||
print('Exception')
|
||||
|
||||
try:
|
||||
struct.unpack('1', 'xx')
|
||||
except:
|
||||
print('Exception')
|
||||
|
||||
try:
|
||||
struct.unpack_from('1', 'xx')
|
||||
except:
|
||||
print('Exception')
|
||||
|
||||
Reference in New Issue
Block a user