8000 py: Fix two segfaults due to accessing uninitialized memory. by smurfix · Pull Request #18732 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@smurfix
Copy link
Contributor
@smurfix smurfix commented Jan 27, 2026

Summary

Accessing obj->subobj[0] without verifying that it contains a valid object (instead of a type, or a non-initialized object) is not a good idea.

Testing

My MoaT package has extensive MicroPython testcases. Before applying this PR the MicroPython process reliably segfaulted. This no longer happens.

Closes #17117 .

@codecov
Copy link
codecov bot commented Jan 27, 2026

Codecov Report

❌ Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 98.41%. Comparing base (be15be3) to head (e17e69a).

Files with missing lines Patch % Lines
py/objexcept.c 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #18732      +/-   ##
==========================================
- Coverage   98.41%   98.41%   -0.01%     
==========================================
  Files         171      171              
  Lines       22324    22329       +5     
==========================================
+ Hits        21971    21975       +4     
- Misses        353      354       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
github-actions bot commented Jan 27, 2026

Code size report:

Reference:  docs/mimxrt: Add docs for mimxrt.Flash. [be15be3]
Comparison: tests: Update for minimal MicroPython. [merge of e17e69a]
  mpy-cross:   +48 +0.013% 
   bare-arm:   +32 +0.057% 
minimal x86:   +47 +0.025% 
   unix x64:   +64 +0.007% standard
      stm32:   +24 +0.006% PYBV10
      esp32:  +116 +0.007% ESP32_GENERIC
     mimxrt:   +24 +0.006% TEENSY40
        rp2:   +40 +0.004% RPI_PICO_W
       samd:   +24 +0.009% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:   +36 +0.008% VIRT_RV32

Accessing obj->subobj[0] without verifying that it contains a valid object
(instead of a type, or a non-initialized object) is not a good idea.

Signed-off-by: Matthias Urlichs <matthias@urlichs.de>
Test basics/subclass_native_exc_noinit.py segfaults without them.

Signed-off-by: Matthias Urlichs <matthias@urlichs.de>
@smurfix
Copy link
Contributor Author
smurfix commented Jan 28, 2026

Added testcases to exercise the problem; one of them manages to reproduce the crash.

I have no idea why the stackless test fails (works on my system).

The test required `super().__new__` to exist, which the minimal build
doesn't have.

Signed-off-by: Matthias Urlichs <matthias@urlichs.de>
@smurfix
Copy link
Contributor Author
smurfix commented Jan 28, 2026

While it might be possible to further improve the diff coverage, IMHO that effort is spent more productively elsewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Segfault in mp_obj_exception_add_traceback

1 participant

0