Commit Graph
613 Commits
Author SHA1 Message Date
Henrik Rydgård 5d77d5daff Merge pull request #22229 from hrydgard/psp-file-attrs
Report PSP file attributes rather than the host's
2026-09-05 13:48:15 -06:00
Henrik Rydgård 86de3307fb Merge pull request #22230 from hrydgard/sceFont-install-fonts
Install sceFont fonts off the disc when we don't have them in the NAND folder
2026-09-05 11:46:56 -06:00
Henrik RydgårdandClaude Opus 5 0e6614cf19 Report PSP file attributes rather than the host's
DirectoryFileSystem passed the host's permission bits and directory
size straight through to the game. The PSP has neither - its FAT driver
makes a mode up from the entry type and whether it's writable, and
reports no size for a directory. So a game saw 0644/0755 and a 4096
byte directory on Linux, but 0664/0777 and 0 on Windows, where the file
layer already synthesizes those bits.

Now both platforms report what the PSP does: 0777 for directories, 0664
for writable files, 0444 for read-only ones, and no size on a
directory. The parent ".." entry keeps its 4096, which is what the
hardware reports for that one.

Also fixes the synthetic PSP directory entry using 0x777 where 0777 was
meant.

Fixes io/directory/directory, moved to tests_good.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-05 09:58:10 -06:00
Henrik Rydgård 981250daf3 ISOFileSystem: Don't crash when the image has no ISO9660 volume
The constructor leaves treeroot null when it can't find a CD001 volume
descriptor, but GetFromPath walked into it anyway - TreeEntry *entry = treeroot;
then entry->valid - so any path lookup on a failed mount dereferenced null.

Reachable from the firmware installer, which mounts whatever file it's handed
and asks for PSP_GAME/SYSDIR/UPDATE without consulting Error() first. Point it
at a PlayStation disc image, whose descriptor sits behind a Mode 2 subheader and
so fails the signature check, and PPSSPP goes down. Identify_File checks for
CD001 before reporting PSP_ISO, so the game browser was never exposed.

Return null instead, which is what the rest of the function already does for a
path that isn't there, and what every caller expects.
2026-09-05 09:47:00 -06:00
Henrik Rydgård 5d608e39a3 Merge pull request #22223 from hrydgard/iso-metadata-hardening
Clamp ISO metadata and file sizes to the max possible extent
2026-09-05 09:28:29 -06:00
Henrik RydgårdandClaude Opus 5 fbdb54300e Put a ceiling on the CSO frame size
Follow-up to #22208, which bounded the index table but left the frame
size itself unbounded - readBuffer and zlibBuffer are sized straight
from it, so a 96-byte header could still ask for a couple of gigabytes.
Harmless enough on 64-bit, where the pages never get touched, but a
32-bit build would just fail the allocation.

Real images use 2KB to 64KB frames, so 16MB leaves plenty of headroom.
All 19 CSOs I have on hand still load.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JvJR8oJNSCimCM9KXVLjfq
2026-09-04 13:10:54 -06:00
Henrik Rydgård 2994145f86 ISOFileSystem: Don't copy out uninitialized stack on a failed block read
ReadFile and the read-path-table ioctl both read a sector into a stack buffer
and memcpy it to the destination without checking whether the read succeeded.
FileBlockDevice::ReadBlock returns false on a short read and leaves the buffer
untouched, so a read past the end of a truncated or crafted image copies 2KB of
uninitialized host stack into guest-visible memory.

Zero the buffer on failure, and bail out of the ioctl if the volume descriptor
can't be read instead of using a garbage path table length. The constructor
already checked that same read.

ReadBlocks writes straight into the caller's buffer, so a partial read there
leaves stale data rather than host memory - left alone deliberately, since
zeroing it would throw away the valid prefix on a truncated image.
2026-09-04 13:02:57 -06:00
Henrik Rydgård 9c1f55ed76 ISOFileSystem: Clamp file sizes to what the image actually contains
The size in an ISO directory record is untrusted, and callers allocate host
buffers from it - GetISOGameID and ReadFileToString did so directly until the
previous commit, and ReadFile clamps reads to the claimed size rather than to
the image.

We've warned about out-of-range extents since c766536914, but deliberately kept
the file, and rounded down so the warning wouldn't fire on borderline images.
Keep that behavior and just clamp the recorded size to the bytes that really
exist. For a well-formed file the extent always fits within its sectors, so this
never triggers; for a truncated one the game keeps booting instead of losing the
file entirely.
2026-09-04 12:59:24 -06:00
Acts1631 095480bcb9 Reject overflowing CSO index sizes
Keep CSO frame and block counts wide until validating their 32-bit

representation, preventing numFrames + 1 from wrapping. Also reject

index tables that cannot fit in the source file or host size_t before

allocation and indexing.
2026-09-03 10:06:35 -04:00
Henrik Rydgård 1295512866 MetaFileSystem: also warn against reordering existing mounts
The positional serialization means swapping two Mount() calls breaks every old
savestate just as thoroughly as adding one does, so say so. Also note that the
mount order spans more than MountFileSystems() - the UMD mounts are added first,
by MountGameISO, before we get there.
2026-08-31 00:23:53 +02:00
Henrik Rydgård 7b409af50f MetaFileSystem: spell out how to add a mount without breaking savestates
The positional serialization means adding a mount silently invalidates every
existing savestate unless its prefix is added to the skip list, which is exactly
how flash1: broke them. Write down the rule, and note that renaming or removing
a mount isn't something this scheme can handle at all.
2026-08-30 23:59:06 +02:00
Henrik RydgårdandClaude Opus 5 729653bf42 Fix loading savestates made before flash1: was mounted
78ef1eae82 added a flash1: mount, but MetaFileSystem::DoState serializes the
mounts positionally - one section each, with no length to skip by - so a state
written before that commit has one section fewer than we now have mounts.

The existing count check assumed a single missing entry could only be pfat0:,
which was the previous mount added this way. So it took the skipPfat0 path,
skipped pfat0's section while still only looping n times, and ended up making
n-1 DoState calls against n sections. Everything after that read shifted, and
the load died with "Failure at DirectoryFileSystem".

Make the "these were added later" set explicit and ordered instead, and iterate
over the mounts rather than over the saved count, so the number of DoState calls
matches the state regardless of which of them are missing.

Verified against Wipeout Pure (UCUS98612): both save slots report n=9 against 10
mounts and fail to load before this, and load after, in both the app and headless.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DCPmm7FoQUoqrbMdhfqhQ2
2026-08-30 23:52:09 +02:00
Henrik Rydgård b3a2178a5c ImDebugger: Show per-thread current directory in threads view 2026-08-24 10:21:27 +02:00
Henrik Rydgård 78ef1eae82 Instead of flash0directory, have a NAND subdirectory under PSP, where you can keep flash0, flash1 etc.
Also make it configurable via command line.
2026-08-24 09:53:37 +02:00
Henrik Rydgård 786a1530de Correct host0: mount 2026-08-24 09:30:44 +02:00
Henrik Rydgård b437ba0fc6 MetaFileSystem: Add subdirectory mounts 2026-08-24 09:30:44 +02:00
Henrik RydgårdandClaude Opus 5 396f9e802d GameInfoCache: report the firmware updater bundled on a game disc
Adds GameInfoFlags::BUNDLED_UPDATE_INFO, holding the version, title, size
and timestamp of the updater in PSP_GAME/SYSDIR/UPDATE. It comes from the
PARAM.SFO and the directory entry next to the archive, so it's a couple of
small reads on the ISOFileSystem the worker already has open - no
decryption, and DATA.BIN itself is only sniffed for its magic. Only
computed for ISOs; everything else is marked complete with an empty struct.

ISOFileSystem now parses the date out of the ISO9660 directory record,
stored as Unix UTC seconds and reported as the PSP's atime/ctime/mtime.
Those used to always read back as zero, so games calling sceIoGetstat on a
UMD file saw 1900 where hardware gives the mastering date.

Shown on GameScreen as e.g. "Firmware update on disc: 6.60 (2011-10-05),
25.6 MB".

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0149QcTVgZEXKXbgHyvXF4ZY
2026-08-23 16:44:38 +02:00
Henrik Rydgård c5e4d0d90d Rename the get-memory-pointer functions to make it clear where CPU exceptions can happen. 2026-08-12 14:06:16 +02:00
Henrik Rydgård f15f8453f0 ISOFileSystem: fix path table re-read bug and validate directory entry size
Ioctl's ISO9660 path table read re-read sector `block` (the first
sector, already consumed by the preceding ReadBlocks) for the trailing
partial sector instead of `block + blocks`, returning duplicated data
from the start of the table instead of its actual tail.

ReadDirectory() advanced by the raw on-disk dir.size without checking
it's at least as large as the record's own header+identifier. A
crafted directory sector could set dir.size = 1 repeatedly, making the
loop reinterpret the same overlapping bytes as many separate entries -
allocating far more TreeEntry objects than the sector's actual size
should allow.
2026-08-11 08:57:15 +02:00
Henrik Rydgård c329363a7d tlzrc: fix undersized probability-table arrays in the LZRC decoder
rc_bittree()/rc_number() can index bm_dist_bits up to column 50 and
bm_dist up to row 43 (when decoding a "long distance" match, i.e.
match_len > 2), but the arrays were only sized for 39 and 18
respectively. A crafted LZRC-compressed block (reachable via
NPDRMDemoBlockDevice::ReadBlock) could drive these indices out of
range, corrupting adjacent probability tables within the same
LZRC_DECODE struct via rc_bit()'s read-modify-write. Size the arrays
for the indices the algorithm can actually produce, and initialize
them via sizeof() so the memset in rc_init stays correct.
2026-08-11 08:57:15 +02:00
Henrik Rydgård 93a8b0e501 VirtualDiscFileSystem: reject ".." in .ppsspp-index.lst entries
fileName is taken verbatim from the index file (only a leading slash
is stripped) and then used essentially unsanitized to build a path
under basePath (GetLocalPath() is a plain string join, unlike
MetaFileSystem::RealPath which does collapse ".." for normal game file
access). A crafted index file - these virtual-disc folders are commonly
shared/downloaded as homebrew - could use a ".." component to make
PPSSPP probe or open arbitrary host files/directories outside the
intended folder just by loading it. Reuse the existing
HasParentDirComponent() helper (already used for the same purpose in
GameManager's zip extraction) to reject such entries.
2026-08-11 08:57:15 +02:00
Henrik Rydgård a82043eb9d CISOFileBlockDevice: reject frame/block count mismatches
numFrames and numBlocks are derived from the same attacker-controlled
64-bit total_bytes field, but independently truncated to 32 bits using
different divisors (frameSize vs. the fixed 2048-byte block size).
With extreme total_bytes/block_size combinations the two truncations
can disagree so that numBlocks (which gates ReadBlock's bounds check)
describes more blocks than numFrames actually covers - ReadBlock then
indexes the numFrames+1-sized `index` array one or more elements past
its end. Reject any header where this could happen before allocating
anything.
2026-08-11 08:57:15 +02:00
Henrik Rydgård e94463b4b6 NPDRMDemoBlockDevice: validate untrusted PBP header/table fields
The block table read from an NPDRM PBP's PSAR blob is only reversibly
XOR-scrambled, not otherwise validated, so a crafted file fully
controls table_[block].size/offset and the header's LBA/block-size
fields. Several of these were used without checks:

- table_[block].size could exceed blockSize_, causing ReadAt and the
  KIRK cipher update to write past the end of blockBuf_/tempBuf_ (both
  allocated as exactly blockSize_ bytes) - a heap buffer overflow.
- The block index derived from blockNumber (which can come from an
  attacker-influenced /sce_lbn.../_size... raw sector open) was never
  bounds-checked against numBlocks_ before indexing table_[].
- blockLBAs_ could be 0, dividing by zero both when computing
  numBlocks_ and when computing the block index in ReadBlock.
- lbaSize_ could underflow if lbaEnd < lbaStart, and tableSize_
  (numBlocks_ * sizeof(table_info)) was computed in 32-bit, so a large
  numBlocks_ could wrap it to a small value - passing the "did we read
  the whole table" check while only actually reading (and
  descrambling) a small prefix, leaving the rest of the table_ array
  as untouched, uninitialized heap memory that ReadBlock() would later
  trust.

Reject all of these instead.
2026-08-11 08:57:15 +02:00
Henrik Rydgård db30fabf03 Add a setting (defaulting to false) for enabling file handler plugins 2026-08-03 11:24:36 +02:00
Henrik Rydgård 317a06f2f6 Revert "Delete the ability to load file handler plugins from extracted game folders"
This reverts commit e806192154.
2026-08-03 11:22:05 +02:00
Henrik Rydgård 6d43b6f531 Fix OOB read/write via negative seek wrap in VFSFileSystem
SeekFile stored a signed s32 position into the unsigned size_t seekPos,
so a negative position (e.g. from a truncating s32 cast of a large
lseek offset) wrapped seekPos to near 2^64. ReadFile's clamp arithmetic
then also wrapped, driving a memcpy from a wild pointer.

- Clamp the computed seek position to 0 in SeekFile.
- Clamp the read size against the remaining data in ReadFile, returning
  0 when seekPos is at or past the end.
2026-08-01 13:16:21 +02:00
Henrik Rydgård b7b96c3374 Fix LZRC decompressor heap overflow and add unit test
The LZRC decompressor's only bounds check for output (and input) was a
debug-only _dbg_assert_msg_, which is a no-op in release builds. The
NPDRM demo block device also passed a hardcoded 1 MiB output length
while the real destination buffer (blockBuf_) could be as small as 2048
bytes, allowing a crafted NPDRM image to trigger an unbounded heap
overflow during game load.

Changes:
- rc_putbyte/rc_getbyte now enforce real bounds and set an error flag
  instead of relying on debug asserts; decompression aborts with -1 on
  overflow or truncated input.
- normalize() reads via rc_getbyte so it stays in bounds.
- Plain-text path clamps the copy size to both the output buffer and the
  remaining input (and no longer interprets the size as signed).
- NPDRMDemoBlockDevice::ReadBlock passes blockSize_ (the real buffer
  size) instead of 0x00100000 to lzrc_decompress.
- Add unittest/TestLzrc (synthetic input, no test data files): checks the
  plain-text clamp, truncated input, and output overflow all fail safely.
- AGENTS.md: note to reuse existing format handlers/decompressors before
  writing new ones.
2026-07-31 20:54:13 +02:00
Henrik Rydgård e806192154 Delete the ability to load file handler plugins from extracted game folders
If there's demand for this feature, we'll bring it back and put it
behind a developer option.

Fixes vuln #7 from the recent collection
2026-07-31 20:35:12 +02:00
Henrik Rydgård 6fb48fd45a Fix heap buffer overflow in CSO block device from crafted index table
A crafted .cso compressed ISO could trigger a heap buffer overflow on any
sector read, reachable via ordinary gameplay.

Two root causes:
1. Unvalidated frame index deltas. ReadBlock/ReadBlocks computed a
   compressed read range from two adjacent frame-index-table entries.
   With non-monotonic entries, compressedReadEnd - compressedReadPos
   underflows as u64, producing a huge read size that fileLoader->ReadAt()
   wrote into the fixed-size readBuffer.
2. hdr.align (indexShift, 0-255) used as '1 << indexShift' was undefined
   behavior at >= 32, and frameSize + (1 << indexShift) could wrap,
   undersizing the buffer while inflate() was configured with the full
   frameSize.

Fixes:
- Validate the index table is monotonically non-decreasing in the
  constructor.
- Reject files with indexShift > 20.
- Use unsigned shift for buffer size math and store readBufferSize.
- Clamp compressed read sizes to readBufferSize in both ReadBlock and
  ReadBlocks.
2026-07-31 20:35:12 +02:00
Henrik Rydgård 4bf36fc7f8 Add command line option --vsh to try to boot the VSH. Logspam reduction, improve printf logs. 2026-07-27 14:58:59 +02:00
Henrik Rydgård 2d8de4c1bf Improve error checking on game launch.
See #21886
2026-07-08 12:04:15 +02:00
Henrik Rydgård e9d5e451fb Avoid some unnecessary error reporting while loading ISOs for the file browser 2026-05-31 23:31:06 +02:00
Henrik Rydgård 7309c477d1 Logging change 2026-05-28 10:55:24 +02:00
Henrik Rydgård 935a50ac59 ISO file system: Clean out version numbers from filenames.
Followup to #21599
2026-04-27 12:36:58 +02:00
whatev.indus f73b27c69d Support loading PSP prototype DVD-R disc dumps directly
Some preserved PSP prototype builds were distributed as DVD-R images that contain the actual UMD data inside USER_L0.IMG and, for dual-layer titles, USER_L1.IMG. These images previously required manual extraction, renaming, or concatenation before PPSSPP could load them.

Add support for recognizing these DVD-R wrapper layouts and exposing the embedded UMD image through the normal disc loading path. This includes both ISO-based wrappers and UDF-based wrappers, so preserved prototype dumps can be opened directly without conversion.

This makes PPSSPP compatible with a wider range of preserved developer disc images without relying on title-specific handling.

The primary importance of this patch is to encourage preserving 1:1, perfect disc image dumps in the manner of Redump.org.

This patch has been successfully tested on the following DVD-R ISOs:
https://hiddenpalace.org/Rock_Band_Unplugged_(Dec_10,_2008_prototype)
https://hiddenpalace.org/WipEout_Pulse_(May_4,_2007_prototype)
https://hiddenpalace.org/Lara_Croft_Tomb_Raider:_Anniversary_(May_19,_2007_prototype)
https://hiddenpalace.org/Heatseeker_(Jan_15,_2007_prototype)

Fixes #15547.
2026-04-26 19:44:49 -07:00
Henrik Rydgård b8463b9203 Fix assorted warnings, bump Cargo.lock 2026-03-24 10:26:49 -06:00
Henrik Rydgård 6377c0bb06 Implement optional dumping of NPDRM isos (PBP demos) on game startup 2026-03-19 16:07:24 +01:00
Henrik Rydgård 0e55129fab Prepare for dumping NPDRM isos, use shared_ptr to manage lifetime of BlockDevice 2026-03-19 13:59:04 +01:00
Henrik Rydgård e5a226a309 Correct bugs in CSO reader 2026-02-26 10:37:12 +01:00
Henrik Rydgård b7ad74d309 MetaFileSystem: Turn another argument into string_view 2026-02-25 00:52:25 +01:00
Henrik Rydgård 22bfa0087c Minor code cleanup 2026-02-25 00:52:25 +01:00
Henrik Rydgård dac2407a36 sceIo: Add support for microseconds in filetimes (not implemented in platforms yet) 2026-02-23 11:04:17 +01:00
Henrik Rydgård b75c416bc1 Some error message cleanup 2026-02-18 14:42:41 +01:00
Henrik Rydgård 19a0441299 Fix crash in NPDRM iso detection (by rejecting invalid values and checking the header) 2026-02-17 15:27:56 +01:00
Henrik Rydgård f8077347e4 FileSystems: Change multiple internal functions to take std::string_view 2026-02-06 12:31:49 +01:00
Henrik Rydgård c85496c84d ISOFileSystem: Some const correctness 2026-02-06 12:00:53 +01:00
Henrik Rydgård f2116c4236 Start using string_view in MetaFileSystem 2026-02-06 11:51:40 +01:00
Henrik Rydgård 841e4c8564 Add various checks trying to avoid various crashes found in Google Play crash reports. 2026-02-05 11:12:53 +01:00
Henrik Rydgård 4fb3a0e370 Bubble up more error messages to the user 2026-01-29 00:25:25 +01:00
Henrik Rydgård 24f2deeb2e Improve file identification.
Fixes #21154
2026-01-28 10:21:09 +01:00