Skip to content

fix: crash on out-of-bound access when loading cheats#718

Merged
frysee merged 3 commits into
LoveRetro:mainfrom
nborodikhin:fix/stack_corruption_on_cheat_loading
May 12, 2026
Merged

fix: crash on out-of-bound access when loading cheats#718
frysee merged 3 commits into
LoveRetro:mainfrom
nborodikhin:fix/stack_corruption_on_cheat_loading

Conversation

@nborodikhin
Copy link
Copy Markdown

@nborodikhin nborodikhin commented May 9, 2026

Summary

I ran into a crash when running a debug build on the device with picodrive core. The crash is caused by populating a fixed size array without proper size check.

On game load, Cheat_getPaths() creates a list of paths to try to load cheats from. 5 entries are pre-configured, and the rest are dynamically populated using the extensions supported by the emulator core. The issue is that some predefined paths (like glob) are added to the list without proper checks after the core extensions are processed, and that causes writing outside of array memory.

Note that Picodrive core has 16 extensions supported, but there are upstream retroarch cores that support up to 42 extensions.

Change

  • Cheat_getPaths():
    • increase the size of the cheat paths list to 48 paths
    • when processing extensions, reserve 3 entries for predefined paths/masks
  • OptionCheats_openMenu():
    • using menu index i (passed in as a position parameter) to access cheat by index
    • iterated with j but indexed both cheatcodes.cheats and OptionCheats_menu.items with i

Test plan

  • debug build of minarch runs SMS game with picodrive

@nborodikhin nborodikhin changed the title fix: stack corruption and index bug in cheat loading fix: crash on out-of-bound access when loading cheats May 9, 2026
@nborodikhin nborodikhin marked this pull request as ready for review May 9, 2026 22:04
Comment thread workspace/all/minarch/minarch.c Outdated
@frysee frysee force-pushed the fix/stack_corruption_on_cheat_loading branch from d84e8f6 to 1d8a592 Compare May 12, 2026 22:46
@frysee frysee merged commit 02d3dc0 into LoveRetro:main May 12, 2026
62 checks passed
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.

2 participants