circuitpython/tests/micropython/ringio_big.py
Jeff Epler 0615d13963 py/objringio: Detect incorrect constructor calls.
ringbuffer.size must be at least 2, and is a 16-bit quantity.

This fixes several cases including the one the fuzzer discovered, which
would lead to a fatal signal when accessing the object.

Fixes issue #17847.

Signed-off-by: Jeff Epler <jepler@gmail.com>
2025-08-15 01:21:25 +10:00

29 lines
603 B
Python

# Check that micropython.RingIO works correctly.
import micropython
try:
micropython.RingIO
except AttributeError:
print("SKIP")
raise SystemExit
try:
# The maximum possible size
micropython.RingIO(bytearray(65535))
micropython.RingIO(65534)
try:
# Buffer may not be too big
micropython.RingIO(bytearray(65536))
except ValueError as ex:
print(type(ex))
try:
# Size may not be too big
micropython.RingIO(65535)
except ValueError as ex:
print(type(ex))
except MemoryError:
print("SKIP")
raise SystemExit