Skip to content

Fix/emulator rom offset validation - #402

Draft
networkfusion wants to merge 3 commits into
n64brew:developfrom
networkfusion:fix/emulator-rom-offset-validation
Draft

networkfusion wants to merge 3 commits into
n64brew:developfrom
networkfusion:fix/emulator-rom-offset-validation

Conversation

@networkfusion

@networkfusion networkfusion commented Aug 26, 2026 •

Copy link
Copy Markdown
Collaborator

Description

This PR just describes a potential fix. We need to actually fix the underlying issue!

rom_offset is parsed from an untrusted, user-editable INI file and cast
directly to uint32_t. Flashcart loaders (sc64, 64drive, ed64 v/x-series)
compute MiB(64) - rom_offset for a bounds check; if rom_offset exceeds
MiB(64) this subtraction wraps to a huge value, making the check pass
when it shouldn't and leading to an out-of-bounds SDRAM write via
ROM_ADDRESS + rom_offset.

Fix: reject any parsed rom_offset >= MiB(64) at the point of parsing,
before it reaches the flashcart loaders.

load_file() (used for the rom_offset path) has no extended-addressing
support in any flashcart implementation; it only ever writes within the
primary 64MB SDRAM window. The 78MB ceiling only applies to full-ROM
loading via load_rom(), a separate code path that doesn't use rom_offset.

Motivation and Context

How Has This Been Tested?

Screenshots

Types of changes

  • Improvement (non-breaking change that adds a new feature)
  • Bug fix (fixes an issue)
  • Breaking change (breaking change)
  • Documentation Improvement
  • Config and build (change in the configuration and build system, has no impact on code or features)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

You agree with the license terms and that other license types may be granted with permission of the original N64FlashcartMenu project license holders.

Signed-off-by: GITHUB_USER <GITHUB_USER_EMAIL>

Summary by CodeRabbit

  • Bug Fixes
    • ROM offset overrides are now accepted only when they contain a complete unsigned integer below 64 MiB. Invalid, partially parsed, or out-of-range values leave the default offset unchanged.

rom_offset is parsed from an untrusted, user-editable INI file and cast
directly to uint32_t. Flashcart loaders (sc64, 64drive, ed64 v/x-series)
compute MiB(64) - rom_offset for a bounds check; if rom_offset exceeds
MiB(64) this subtraction wraps to a huge value, making the check pass
when it shouldn't and leading to an out-of-bounds SDRAM write via
ROM_ADDRESS + rom_offset.

Fix: reject any parsed rom_offset >= MiB(64) at the point of parsing,
before it reaches the flashcart loaders.
load_file() (used for the rom_offset path) has no extended-addressing
support in any flashcart implementation; it only ever writes within the
primary 64MB SDRAM window. The 78MB ceiling only applies to full-ROM
loading via load_rom(), a separate code path that doesn't use rom_offset.
@coderabbitai

coderabbitai Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 08f91e8c-fc66-49d5-a9eb-dc79889cf76e
Commits

Reviewing files that changed from the base of the PR and between 772a7ad and 13ea062.

Files selected for processing: 1
  • src/menu/cart_load.c

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

Walkthrough

The ROM offset override now applies only when the value parses completely and is less than 64 MiB. Invalid, partially parsed, and out-of-range values leave the default offset unchanged.

Changes: ROM offset validation

Layer / File(s) Summary
Enforce ROM offset bound
src/menu/cart_load.c
The validation rejects parsed offsets at or above 64 MiB. Comments describe the write window and the bound.

Estimated code review effort: 2 (Simple) | ~5 minutes

Change: Bug fix

Suggested labels: bug

Merge Risk: Minimal · up to 13ea0

The PR applies the intended 64 MiB ROM offset bound without an identified current-head defect.

Architecture risk: Low · up to 13ea0

The change affects 1 system.

Changed systems: src

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — src (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in src/menu/cart_load.c: The rom_offset validation now rejects parsed values of MiB(64) or greater; previously, any completely parsed value was accepted. The added comments describe the 64 MiB write window and the reason for the bound.
Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly identifies the main change: validation of the emulator ROM offset. It is concise and specific enough for the pull request history.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 1 files.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
Simplify code
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

This branch has not been deployed

No deployments
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.

1 participant