Skip to content

Main gets a load error for empty ROMs and unread large-ROM headers, more zip tests and a clearer ZIP message - #40

Merged
redcode9 merged 7 commits into
features/state-of-the-art-development/mainfrom
features/state-of-the-art-development/wip/rom-loading
Nov 16, 2026
Merged

redcode9 merged 7 commits into
features/state-of-the-art-development/mainfrom
features/state-of-the-art-development/wip/rom-loading

Conversation

@redcode9

Copy link
Copy Markdown
Owner

Review-fix round for wip/rom-loading. The branch was fast-forwarded to main 391f5e9 first, so this PR holds six commits after it. Two fix the loose-ROM loader in load_gamepak_raw(), one adds zip test cases, one rewords the ZIP error message in the five tables, and two correct the EXT-2.2 ticket text and the changelog. zip_rom.c, zip.c and the code that picks the message do not change.

What was wrong and what changed:

  • An empty .gba, .agb or .bin file counted as a loaded game (41caaa9). For a 0-byte file, or one whose size cannot be read, load_gamepak_raw() returned 0, and every caller of load_gamepak() takes 0 as success. The menu then reset the GBA on whatever gamepak_rom held: the previous game, or a blank cartridge that hangs in the BIOS when nothing was loaded yet. The empty file also went into Recent ROMs. Now the file is closed and the load returns -1, so the callers show the load error, as zip.c already does for an empty zip entry. 1.4.3 had the same bug, so CHANGELOG.md gets a new Unreleased > Fixed bullet. tests/test_memory_backup.c gets test_empty_rom_fails_to_load.
  • A ROM too big for the buffer still loaded when its header did not read (d7125a6). Such a ROM is read in pages while the game runs, and only its first 0x100 bytes are read at load time. The result of that read was ignored, so a failed or short read kept the previous game's header in gamepak_rom, and the load still returned the file size. Now the load fails with -1 and closes the file. The function comment, which says a failed or short read fails the load, is true again. tests/test_memory_backup.c gets test_large_rom_without_header_fails_to_load. It runs last, because the stub's ROM reads keep failing after it. The round-1 fixer found this bug next to the empty-ROM fix, and the round-1 review asked for it.
  • The EXT-2.2 ticket text still gave a damaged zip the code -3 (4c67b89). Since SAV-1.5, -3 is LOAD_GAMEPAK_CANCELLED, and the code returns LOAD_GAMEPAK_ZIP_DAMAGED (-4, memory.h). A tester checking the ticket would have looked for the cancel code. The "Cosa" line of EXT-2.2 in docs/BACKLOG.md now names -4 and says -3 stays the cancel code. The EXT-2.2 note in docs/wip/rom-loading.md records it too. A second finding reported the same -3, and this commit fixes both.
  • The zip tests never loaded a stored ROM smaller than one read with more archive bytes after it (d3501da). Without the clip to the entry's size, such a ROM would read past its entry and fail its CRC, or write past a small output buffer, and the tests would still pass. tests/test_zip_rom.c now loads a 1000-byte stored entry followed by the rest of the archive, in 4 KiB and 128 KiB reads with a 1000-byte output buffer. It also checks that method 6 is unsupported, and that a real extra field of 0x8000 bytes before an intact entry is refused while one of 0x7FFF bytes loads. No code changed.
  • The changelog promised the ZIP message in the file browser, but the browser shown at startup gives the generic load error (4c67b89, then 77cac8f). The first ROM of a session is usually picked there. EXT-2.2 chose to keep the generic message on the startup paths, so main.c stays as it is and the docs now say what the code does:
    • CHANGELOG.md says Load game and Load state from file in the menu show the ZIP message, and a .zip picked in the browser shown at startup, or passed by a launcher, still gets the generic load error.
    • The "Cosa" line of EXT-2.2 called all three user_main paths "the command line". It now names them: the command line, roms/game.gba and the browser shown at startup.
    • The EXT-2.2 note says to check the messages from «Carica gioco» or «Carica salvataggio da file».
    • The round-1 review found one more mismatch. After the error, «Carica gioco» goes back to the menu, as in 1.4.3 (gui.c:4865-4871 ends in menu_init()), and only «Carica salvataggio da file» opens the list again. The EXT-2.2 acceptance said both go back to the browser, so a tester following it would have logged a false failure. 77cac8f changes the acceptance and the note to say where each one goes back to.
  • A good zip that the loader does not support was called damaged (4573d65). zip_rom refuses an encrypted entry, a method other than stored or deflated, a first entry that is not a ROM and a stored entry with its sizes after the data. zip.c maps all of them to LOAD_GAMEPAK_ZIP_DAMAGED. So a valid archive with a readme first showed "damaged or incomplete", and a player could throw away a good file. EXT-2.2 asks for one message, so the mapping stays the same and only the text changes, in all five tables:
    • eng: "The ZIP file is damaged, incomplete or not supported."
    • ita: "Il file ZIP è danneggiato, incompleto o non supportato."
    • The chs, cht and jpn strings say the same.
    • Both zip bullets in CHANGELOG.md match the new text. That text is new in Unreleased, so it needs no entry of its own.

Tickets whose status changed:

  • None. No story was ticked or unticked.
  • EXT-2.2 stays open: code complete, PSP check pending. Its "Cosa" line and its acceptance text changed to match the code (see above), and its note in docs/wip/rom-loading.md now has the -4 code and the menu entries to test from.

Tests on this host (Windows, clang with a small libc shim as HOST_CC, no make, gcc or PSP SDK):

  • test_zip_rom: passes, plain and with UBSan.

  • Mutation checks on zip_rom.c. Each mutant below makes test_zip_rom stop on an assert, plain and with UBSan:

    • the clip to the entry's size deleted, or changed to size - 1;
    • the extra-field limit removed;
    • > changed to >= in that limit;
    • the method check changed to accept any method up to 8.

    A mutant that dropped the extra-field limit used to survive and is now caught. The branch's earlier 18 mutants of zip_rom.c are all still caught.

  • test_memory_backup cannot be built here, because it compiles memory.c against the PSP SDK headers. Instead:

    • It passes a syntax-only compile with -std=c99 -Wall -Wextra -Werror.
    • load_gamepak_raw(), spliced from this branch's memory.c into a probe with stubbed file I/O, passes plain and with UBSan for: an empty file (-1, closed once); a 3-byte ROM (returns 3); a file that does not open (-1); a large ROM whose header reads (returns its size, keeps the file open); a large ROM whose header read fails or returns 0x80 bytes (-1, closed).
    • The probe fails, plain and with UBSan, with the empty-file check removed, and with the header read unchecked again.
  • The five message tables: each changes one line, its LF line ending is kept, the CRLF and LF counts are the same as at 391f5e9, and every new string encodes as GBK.

  • check-messages, check-tree (forbidden names, module tests and git diff --check included), check-module-tests, check-menu-layout, check-lifecycle, check-video and check-performance pass, run with PYTHON=python from CR-stripped copies where needed.

  • check-core, check-render, check-test-roms and check-eboot pass, but skip their parts that need tools not installed here (arm-none-eabi-gcc, PPSSPPHeadless and the reference emulator).

  • tests/test_browser_text.py and tests/test_check_names.py pass.

  • tests/test_ui_golden.py passes with the wip/ui-ge toolkit's shim, used read-only. With this branch's own shim it fails 0 != 225, because that shim has no working stdout. It fails the same way with the message tables of 391f5e9, so this is a limit of the shim, not of the new text.

  • git diff --check 391f5e9..HEAD: clean. The diff and the commit messages hold no forbidden name and no attribution line.

  • The two new memory tests and the new zip cases are in files already in HOST_TESTS and HOST_SANITIZE_TESTS, so no Makefile change was needed.

  • CI will run make check, make test-sanitize, make check-cbmc and both PSP builds on this PR. CI is the first place test_memory_backup runs with its two new tests.

Not verified here:

  • make check, make test-sanitize with gcc and ASan, and check-cbmc: this machine has no make, gcc or CBMC. check-rom-link.sh did not run either: the reference emulator it needs is not installed here.
  • No PSP build of memory.c with -Werror. The new lines add no variable and use FILE_CLOSE, which this function already uses. They compare a u32 with 0, and sceIoRead's int result with the int 0x100, so no sign-compare warning is expected.
  • Nothing ran on a PSP or in PPSSPP:
    • The empty .gba error path was not seen on the console.
    • It is not known yet whether the longer ZIP message fits the 440-pixel error popup in all five languages. The longest string is about 55 half-width characters, about 330 px, against 416 px of usable width. That is an estimate, not a test.
    • EXT-2.2's PSP session is still to do.
  • The new Chinese and Japanese wording was not checked by a native speaker.

Files of other branches touched (rule 5):

  • tests/test_memory_backup.c, wip/save-store's SAV-1.4 test. It gets the two new test cases, their calls in main(), a declaration of host_stub_rom_io() and one line in the header comment. It already loads ROMs through the real load_gamepak() of memory.c with stubbed file I/O, which the new cases need.
  • source/src/text/message_{eng,ita,chs,cht,jpn}.h, the shared message tables. Each one changes only this branch's MSG_ERR_ZIP_CORRUPT string, one line per table.
  • CHANGELOG.md (shared): one new Unreleased > Fixed bullet for the empty ROM, and this branch's two zip bullets reworded.
  • docs/BACKLOG.md: only the "Cosa" and acceptance lines of EXT-2.2, this branch's own ticket.
  • load_gamepak_raw() in source/src/memory.c, tests/test_zip_rom.c and docs/wip/rom-loading.md belong to this branch.

Skipped, with the reason (the round-2 review found no blockers or minors and left two optional nits, so the round closed without them):

  • The "Cosa" line of EXT-2.2 says load_file_zip returns LOAD_GAMEPAK_ZIP_DAMAGED "per ogni altro esito". But it still returns -1 when the file does not open or memory runs out (zip.c:64, :77). The wording was already loose before this round, and the code is right. Saying "−1 se il file non si apre o manca la memoria" before the -2 case would fix it.
  • The large-ROM header fix has no changelog line of its own. The bullet "A .gba file that cannot be read in full now fails to load" covers it only loosely, since a ROM too big for the buffer is never read in full on purpose. Widening that bullet to name a large ROM whose header does not read would fix it.
  • The Unreleased section of CHANGELOG.md has a second "### Fixed" heading after "### Known issues" (around line 317). It came from wip/ui-ge (68d4bef), so it was left alone here. Whoever integrates wip/ui-ge or writes the release notes should move its cheat-message bullet into the first "### Fixed" list and delete the second heading.

The branch stays open, so docs/wip/rom-loading.md stays.

A stored ROM smaller than one read, with archive bytes after it, now
loads in a test, so the clip to the entry's size is covered. Method 6
must be unsupported, and a real extra field over 0x7FFF bytes refused
while one of 0x7FFF bytes loads.
load_gamepak_raw() returned the size 0 for an empty file, and every
caller of load_gamepak() takes 0 as success: the GBA was reset on
whatever gamepak_rom held. Return -1, as zip.c already does for an
empty entry.
EXT-2.2 still gave a damaged zip -3, which is LOAD_GAMEPAK_CANCELLED;
the code returns LOAD_GAMEPAK_ZIP_DAMAGED (-4). The changelog promised
the message in every file browser, but the browser shown at startup
and a launcher's ROM keep the generic load error, as the ticket chose.
The message covered every archive zip_rom refuses, so a good .zip with
a readme first, an encrypted one or one with another method was called
damaged or incomplete.
The streamed branch of load_gamepak_raw() ignored the result of its
0x100-byte header read, so a failed read kept the previous game's header
in gamepak_rom and the load still returned the file size.
@redcode9
redcode9 merged commit ba110b0 into features/state-of-the-art-development/main Nov 16, 2026
8 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.

1 participant