QUERY · ISSUE
uctypes incompatibility with OBJ_REPR_B
bug
Port, board and/or hardware
unix, 32-bit, obj_repr_b
MicroPython version
based on v1.27.0-preview-154-g44986b1f04
Reproduction
- Make a build with OBJ_REPR_B
- Look at the uctypes constants
Expected behaviour
All the constants are distinct
Observed behaviour
Some of the constants are duplicates
>>> import uctypes
>>> assert uctypes.INT8 != uctypes.BFINT8
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AssertionError:
Additional Information
See more discussion at https://github.com/micropython/micropython/pull/17688#discussion_r2357500386
Patch to add a REPR_B coverage build to ci.sh:
diff --git a/tools/ci.sh b/tools/ci.sh
index 901059991e..5afe089ccb 100755
--- a/tools/ci.sh
+++ b/tools/ci.sh
@@ -543,6 +543,14 @@ CI_UNIX_OPTS_SANITIZE_UNDEFINED=(
LDFLAGS_EXTRA="-fsanitize=undefined -fno-sanitize=nonnull-attribute"
)
+CI_UNIX_OPTS_REPR_B=(
+ VARIANT=coverage
+ CFLAGS_EXTRA="-DMICROPY_OBJ_REPR=MICROPY_OBJ_REPR_B -Dmp_int_t=int32_t -Dmp_uint_t=uint32_t"
+ MICROPY_FORCE_32BIT=1
+ RUN_TESTS_MPY_CROSS_FLAGS="--mpy-cross-flags=\"-march=x86 -msmall-int-bits=30\""
+
+)
+
function ci_unix_build_helper {
make ${MAKEOPTS} -C mpy-cross
make ${MAKEOPTS} -C ports/unix "$@" submodules
@@ -688,6 +696,15 @@ function ci_unix_32bit_setup {
python3 --version
}
+function ci_unix_coverage_repr_b_build {
+ ci_unix_build_helper "${CI_UNIX_OPTS_REPR_B[@]}"
+ ci_unix_build_ffi_lib_helper gcc -m32
+}
+
+function ci_unix_coverage_repr_b_run_tests {
+ ci_unix_run_tests_helper "${CI_UNIX_OPTS_REPR_B[@]}"
+}
+
function ci_unix_coverage_32bit_build {
ci_unix_build_helper VARIANT=coverage MICROPY_FORCE_32BIT=1
ci_unix_build_ffi_lib_helper gcc -m32
--
2.47.3
Code of Conduct
Yes, I agree
CANDIDATE · ISSUE
uctypes.bytes_at() accepts out-of-range (non-canonical) address and segfaults
bug
Port, board and/or hardware
Unix port
MicroPython version
MicroPython v1.27.0-preview.107.gd1607598f on 2025-09-09; linux [GCC 14.2.0] version
Reproduction
A Python-level exception when the address is obviously invalid, e.g.:
- ValueError/OverflowError for negative/out-of-range addresses, or
- OSError if the runtime chooses to probe and detect unreadable memory on the unix port.
At minimum, reject negative addresses and detect addr + size overflow to avoid trivial VM crashes.
Expected behaviour
import uctypes
ptr = 1 << 48
arr = uctypes.bytes_at(ptr, 8)
print('READ', arr)
Observed behaviour
Program received signal SIGSEGV, Segmentation fault.
#0 qstr_compute_hash(data=0x1000000000000, len=0x8)
#1 mp_obj_new_str_copy(type=mp_type_bytes, data=0x1000000000000, len=0x8)
#2 mp_obj_new_bytes(...)
#3 uctypes_struct_bytes_at(ptr=0x1000000000000, size=0x8)
#4 fun_builtin_2_call(...)
#5 mp_call_function_n_kw(...)
#6 mp_execute_bytecode(...)
...
Additional Information
No, I've provided everything above.
Code of Conduct
Yes, I agree