picogame: validate the original object when the display cast yields NULL - #11306
Merged
Merged
Conversation
pg_get_display(), scene_resolve_target() and Display() cast the display
argument to its busdisplay native base and, when the cast fails, passed the
result straight to mp_arg_validate_type(). mp_obj_cast_to_native_base()
returns MP_OBJ_NULL for anything that is not a BusDisplay (a
FramebufferDisplay, None, a pg.Framebuffer, an int), so the error path
called mp_obj_get_type(NULL) to name the offending type: on RP2040 that
read lands in the ROM's initial stack pointer and yields a TypeError with
a garbage type name, on RP2350 it is a bus fault at 0xF0000006 and the
board hard-faults into safe mode.
Check for MP_OBJ_NULL and validate the object the caller actually passed,
so the message names its real type:
TypeError: display must be of type BusDisplay, not FramebufferDisplay
Verified on a Fruit Jam (RP2350): pg.invert()/pg.render()/pg.Scene() with
a FramebufferDisplay, None and an int all raise the TypeError above instead
of resetting the board; on the unpatched firmware the first call resets it
with SafeModeReason.HARD_FAULT.
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.
pg_get_display(),scene_resolve_target()andDisplay()pass the result ofmp_obj_cast_to_native_base()tomp_arg_validate_type()when the argument is not aBusDisplay(eg. framebuffer). The cast returnsMP_OBJ_NULLin that case and the error path dereferences it - on RP2350 a bus fault and a reset into safe mode instead of aTypeError.Check for
MP_OBJ_NULLand validate the object the caller passed, so the error names its real type (TypeError: display must be of type BusDisplay, not FramebufferDisplay). No change for valid arguments. Verified on a Fruit Jam.