Repository navigation
Main gets a load error for empty ROMs and unread large-ROM headers, more zip tests and a clearer ZIP message - #40
Merged
Conversation
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
merged commit Nov 16, 2026
ba110b0
into
features/state-of-the-art-development/main
8 checks passed
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.
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 inload_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.cand the code that picks the message do not change.What was wrong and what changed:
.gba,.agbor.binfile 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 ofload_gamepak()takes 0 as success. The menu then reset the GBA on whatevergamepak_romheld: 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, aszip.calready does for an empty zip entry. 1.4.3 had the same bug, soCHANGELOG.mdgets a new Unreleased > Fixed bullet.tests/test_memory_backup.cgetstest_empty_rom_fails_to_load.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.cgetstest_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.LOAD_GAMEPAK_CANCELLED, and the code returnsLOAD_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 indocs/BACKLOG.mdnow names -4 and says -3 stays the cancel code. The EXT-2.2 note indocs/wip/rom-loading.mdrecords it too. A second finding reported the same -3, and this commit fixes both.tests/test_zip_rom.cnow 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.main.cstays as it is and the docs now say what the code does:CHANGELOG.mdsays Load game and Load state from file in the menu show the ZIP message, and a.zippicked in the browser shown at startup, or passed by a launcher, still gets the generic load error.user_mainpaths "the command line". It now names them: the command line,roms/game.gbaand the browser shown at startup.gui.c:4865-4871ends inmenu_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.zip_romrefuses 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.cmaps all of them toLOAD_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:CHANGELOG.mdmatch the new text. That text is new in Unreleased, so it needs no entry of its own.Tickets whose status changed:
docs/wip/rom-loading.mdnow 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 makestest_zip_romstop on an assert, plain and with UBSan:>changed to>=in that limit;A mutant that dropped the extra-field limit used to survive and is now caught. The branch's earlier 18 mutants of
zip_rom.care all still caught.test_memory_backupcannot be built here, because it compilesmemory.cagainst the PSP SDK headers. Instead:-std=c99 -Wall -Wextra -Werror.load_gamepak_raw(), spliced from this branch'smemory.cinto 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 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 andgit diff --checkincluded),check-module-tests,check-menu-layout,check-lifecycle,check-videoandcheck-performancepass, run withPYTHON=pythonfrom CR-stripped copies where needed.check-core,check-render,check-test-romsandcheck-ebootpass, but skip their parts that need tools not installed here (arm-none-eabi-gcc, PPSSPPHeadless and the reference emulator).tests/test_browser_text.pyandtests/test_check_names.pypass.tests/test_ui_golden.pypasses with thewip/ui-getoolkit'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_TESTSandHOST_SANITIZE_TESTS, so no Makefile change was needed.CI will run
make check,make test-sanitize,make check-cbmcand both PSP builds on this PR. CI is the first placetest_memory_backupruns with its two new tests.Not verified here:
make check,make test-sanitizewith gcc and ASan, andcheck-cbmc: this machine has no make, gcc or CBMC.check-rom-link.shdid not run either: the reference emulator it needs is not installed here.memory.cwith-Werror. The new lines add no variable and useFILE_CLOSE, which this function already uses. They compare au32with 0, andsceIoRead's int result with the int 0x100, so no sign-compare warning is expected..gbaerror path was not seen on the console.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 inmain(), a declaration ofhost_stub_rom_io()and one line in the header comment. It already loads ROMs through the realload_gamepak()ofmemory.cwith 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'sMSG_ERR_ZIP_CORRUPTstring, 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()insource/src/memory.c,tests/test_zip_rom.canddocs/wip/rom-loading.mdbelong 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):
load_file_zipreturnsLOAD_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..gbafile 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.CHANGELOG.mdhas a second "### Fixed" heading after "### Known issues" (around line 317). It came fromwip/ui-ge(68d4bef), so it was left alone here. Whoever integrateswip/ui-geor 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.mdstays.