bitmapfilter, aesio, analogbufio, floppyio, memorymonitor, busio: dec… - #11385
Merged
Merged
Conversation
…lared type and use disagree bitmapfilter.morph read offset through .u_bool although it is MP_ARG_INT, so only its low byte reached the filter and offset=256 behaved as offset=0. aesio read counter through .u_int although it is MP_ARG_OBJ, so the object's own address went in and a string or None was accepted without complaint. analogbufio.readinto and floppyio.mfm_readinto both asked for read-only buffers and then wrote to them, so a bytes was accepted and filled anyway. floppyio's clear_validity also cleared a local array rather than the caller's. memorymonitor's bucket index runs to the width of a size_t but the array has ALLOCATION_SIZE_BUCKETS entries, so a large enough allocation incremented past the end of it. busio.I2C.writeto_then_readfrom validates in_length and named out_buffer in the error it raises.
Author
|
Testing and diagnostic script. |
tannewt
added this pull request to the merge queue
Sep 14, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Sep 14, 2026
tannewt
added this pull request to the merge queue
Sep 15, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to no response for status checks
Sep 15, 2026
dhalbert
enabled auto-merge
September 15, 2026 15:43
dhalbert
added this pull request to the merge queue
Sep 15, 2026
tannewt
removed this pull request from the merge queue due to the queue being cleared
Sep 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Code written by Claude Code, guided and corrected by @peterbay.
The problem
Six places where the declared type and the use disagree: two arguments read out of the wrong member of
mp_arg_val_t, two buffers asked for read access and then written to, amemsetof a local instead of the caller's array, and an index used one bucket past the end.The changes
bitmapfilter.morphreadoffsetthrough.u_bool. It isMP_ARG_INTin the argument table, so only its low byte reached the filter:offset=256behaved asoffset=0andoffset=257asoffset=1.aesio'scounterwas read through.u_int. It is declaredMP_ARG_OBJwith aMP_OBJ_NULLdefault, so the object's own address went in as the counter and anything at all was accepted — a string,None. Read throughmp_obj_get_int_truncatednow, which is also what rejects those. (The value is stored and never read afterwards, so nothing about the cipher changes; what changes is that a non-integer is refused rather than silently turned into a pointer.)analogbufio.readintoasked for a read-only buffer and then filled it, so abytesor a read-onlymemoryviewwas accepted and written to anyway.floppyio.mfm_readintodid the same with its validity buffer, andclear_validitycleared a local array rather than the caller's, so it did nothing at all.memorymonitor's bucket index ran past its array. The count runs to the width of asize_tbut there are onlyALLOCATION_SIZE_BUCKETSbuckets, so an allocation of 65536 blocks or more incremented past the end, into the fields that follow it in the object.busio.I2C.writeto_then_readfromnamed the wrong buffer in its error. It validatesin_lengthand passedMP_QSTR_out_buffer, so a short input buffer produced a message pointing at the output one.Testing
Seeed XIAO nRF52840 Sense, on two builds differing only by these changes.
morph(..., threshold=True, offset=256)offset=0morph(..., threshold=True, offset=257)offset=1morph(..., threshold=True, offset=255)AES(key, MODE_CTR, iv, counter="nonsense")TypeError: can't convert str to intAES(key, MODE_CTR, iv, counter=None)TypeError: can't convert NoneType to intAES(key, MODE_CTR, iv, counter=7)The
morphrows are the truncation in full: below 256 the low byte and the value are the same number, so the defect only shows once the offset passes it.Four of the six are not in that table, for reasons that have nothing to do with the fixes.
analogbufioandfloppyiohave no HAL on this port and cannot be built here at all.busio.I2Cneeds a bus with pull-ups, which this board has none free for. Andmemorymonitordoes not compile anywhere, which is worth saying on its own.A note on memorymonitor
Nothing enables
CIRCUITPY_MEMORYMONITOR— it is?= 0and no port or board overrides it — and the module has not been built for long enough to stop compiling. Onmaintoday it fails with:AllocationSize.c:m_new_objis called with the object's type as a second argument. That form went away when the object representation changed;mp_obj_mallocis what does both jobs now.__init__.c:mp_obj_new_exception_msg_vlistno longer exists.AllocationAlarm.cfails too.I have not touched any of that here — reviving the module is a separate piece of work, and guessing at it inside a bug-fix patch seemed worse than reporting it. The bucket fix is included because it is correct and because whoever does revive it should not have to find that one as well.
No new translatable strings.