cdvdman: use real media size for out-of-bounds checks - #1763
Open
oMrRexD wants to merge 1 commit into
Open
Conversation
The out-of-bounds read/seek emulation took mediaLsnCount from the ISO9660 PVD "Volume Space Size" field, which describes the ISO9660 volume and not the disc. Discs mastered with that field understated keep data past the end of the volume and read it by raw LBA, which works on real hardware but now fails with SCECdErIPI. Pass the real media sector count from the EE side instead, and fall back to the PVD value when it is not provided.
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.
Pull Request checklist
Note: these are not necessarily requirements
Pull Request description
Fixes #1737.
Problem
#961 added out-of-bounds read/seek emulation, taking the media size (
mediaLsnCount) from the ISO9660 PVD "Volume Space Size" field. That field describes the ISO9660 volume, not the disc. Some discs were mastered with it understating the real size, keeping the bulk of the game data past the end of the declared volume and reading it by raw LBA.On those discs every read of the game data now fails with
SCECdErIPI, so they stopped booting from Beta-2009 onwards. Two redump-verified dumps with the defect:On real hardware these reads succeed: the drive only rejects reads past the physical end of the disc, and those sectors physically exist. Discs of the same engine family whose PVD is correct (e.g. [SLES_544.61], [SLPM_625.25], [SLPM_626.38]) were never affected, so this is a per-disc mastering problem rather than a per-game one.
Change
The emulation from #961 is kept; only the source of the sector count changes to the real media size, which the EE side already knows at launch time:
struct cdvdman_settings_commongains amediaLsnCountfield.sbGetMediaLsnCount(); for ZSO images the uncompressed sector count from the ZISO header is used instead.total_size_in_kb(ziso_total_blockfor ZSO).cdvdman_searchfile_init()prefers that value and falls back to the PVD when it is zero, so any path that does not set it keeps the current behaviour.Games that read past the physical end of the image — the ones #421 was about, e.g. Ratchet & Clank 3 PAL — still get their error, since the check itself is unchanged.
Testing
Builds cleanly with
make clean releasein the officialghcr.io/ps2homebrew/ps2homebrew:mainimage, and passes clang-format 12.Tested on a SCPH-50001/N with the games on USB:
Independent confirmation of the root cause: hex-patching only the PVD Volume Space Size of an affected image to the real sector count also makes it boot on a stock Beta-2245 build.
Not exercised on my side: the SMB and ZSO paths, and Ratchet & Clank 3 — its #421 case triggers in the vid-comic 5 level, and the savedata linked from #389 for reaching it is no longer downloadable.