← index #5427PR #3264
Related · high · value 0.220
QUERY · ISSUE

struct.pack doesn't check for value bounds

openby dimpoloopened 2019-12-16updated 2019-12-19
py-core

Setup: MicroPython v1.11-555-g80df377e9 on 2019-11-04; PYBv1.1 with STM32F405RG

struct.pack('B', 256)  # returns b'\x00'

CPython errors out with struct.error: ubyte format requires 0 <= number <= 255

CANDIDATE · PULL REQUEST

py/binary.c: Bugfix for struct.pack('>Q', 16)

closedby basvsopened 2017-08-12updated 2017-08-15

Without bugfix:

struct.pack('>Q', 16)
b'\x00\x00\x00\x10\x00\x00\x00\x00'

With bugfix:

struct.pack('>Q', 16)
b'\x00\x00\x00\x00\x00\x00\x00\x10'

Also added test-case to tests/basics/struct1_intbig.py; without this merge-request the test will fail on 32-bit platforms.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied