Commit Graph
103 Commits
Author SHA1 Message Date
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
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 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 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 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 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
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 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 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 4fb3a0e370 Bubble up more error messages to the user 2026-01-29 00:25:25 +01:00
Henrik Rydgård 64680a4ebf Add early checks in the various BlockDevice implementations 2025-06-07 12:30:20 +02:00
Henrik Rydgård 77f9a27c35 Add a way for errors to bubble up out of BlockDevice creation 2025-06-07 12:30:20 +02:00
Henrik Rydgård c29e370e29 Remove global state from kirk engine 2025-06-05 22:46:24 +02:00
Henrik Rydgård 6bf8d7d1db Memory safety fixes 2025-05-22 11:10:00 +02:00
Henrik Rydgård c91169e702 Restore removed <algorithm> includes.
Turns out these were needed after all. For some reason, on Windows and
Mac, <algorithm> gets auto-included by something else so I don't notice
when it's missing, and MSVC's include dependency tracker doesn't see it
either.
2024-12-19 09:53:07 +01:00
Henrik Rydgård 3e198c53b2 More include cleanup 2024-12-18 13:57:26 +01:00
Henrik Rydgård 2e53d2f9f9 NPDRM: Logging cleanup, remove assert (turn into debug assert) 2024-11-01 20:10:23 +01:00
Henrik Rydgård f14551ef33 Logging improvement in NPDRMBlockDevice 2024-10-31 00:38:06 +01:00
Henrik Rydgård bd8905aa44 Avoid crashing on PSX EBOOTs renamed to ISO (people try strange things...) 2024-10-25 15:20:08 +02:00
Henrik Rydgård 662b0847c9 Assert instead of crashing if demo ISO decryption fails 2024-10-10 14:56:20 +02:00
Henrik Rydgård e01ca5b057 Logging API change (refactor) (#19324)
* Rename LogType to Log

* Explicitly use the Log:: enum when logging. Allows for autocomplete when editing.

* Mac/ARM64 buildfix

* Do the same with the hle result log macros

* Rename the log names to mixed case while at it.

* iOS buildfix

* Qt buildfix attempt, ARM32 buildfix
2024-07-14 14:42:59 +02:00
Henrik Rydgård d284ad4496 Remove warning for bad CHDs 2024-03-16 20:52:21 +01:00
Henrik Rydgård dad579615b CHD support: Fix accidental hunk re-reads with large chunks. 2024-03-16 20:38:23 +01:00
Henrik Rydgård 3831ec1921 Warn the user about bad CHDs
If they're not created with "chdman createdvd", they will perform really
badly.
2024-01-31 22:15:47 +01:00
Henrik Rydgård 00f53ad767 Handle file type detection of extracted ISO directories better. Reported by Nemoumbra. 2024-01-12 15:37:53 +01:00
Henrik Rydgård 7d114eb29b Remote ISO: Add working support for streaming CHD files over the network 2023-12-29 13:34:22 +01:00
Henrik Rydgård a416d94e38 CHD over http wasn't actually working, disable again until it can be fixed 2023-12-29 12:19:06 +01:00
Herman Semenov 2a31f8c6c0 [Common/Core/HLE] Object out of scope optimization for better codegeneration (lower level scope) 2023-12-20 12:33:56 +03:00
Henrik Rydgård 93c0ef68b6 Add progress bar to CRC calculation 2023-10-28 06:50:57 -05:00
Henrik Rydgård bb33a43d54 Remove superfluous chd_read_header (until we add parent/child chd support) 2023-09-29 11:05:48 +02:00
Henrik Rydgård 64d92c9aa0 Use OpenCFile, for future Android compatibility for chd 2023-09-29 10:16:45 +02:00
Henrik Rydgård ade64171ce Proof-of-concept: libchdr works on Windows 2023-09-29 10:05:19 +02:00
Henrik Rydgård 546f9d7743 Some cleanups and fixes to obscure crashes 2023-09-24 13:05:25 +02:00
Henrik Rydgård eb21a2e6c9 Break out the OSD data holder from Common/System/System.h, into OSD.cpp/h 2023-06-30 17:15:49 +02:00
Henrik Rydgård 266b85d22d Support for extra text in OSD messages (drawn smaller, on darker background) 2023-06-21 01:16:25 +02:00
Henrik Rydgård 7cc8c6cea4 OSD: Add semantics, move the the OSD state to common (while keeping the renderer in the UI). 2023-06-20 14:40:46 +02:00
Henrik Rydgård ee6234ecb6 I18N: Switch to getting categories by index instead of by string lookup
Also gets rid of the shared_ptr usage, and generally makes things nicer.

Needed for later config refactorings, good to get in early.
2023-04-07 10:35:01 +02:00
Henrik Rydgård 9e125eeba7 Remove NotifyUserMessage from Host 2023-03-25 10:32:09 +01:00
Henrik Rydgård 18f828d74b Some zero init, add a null check in TextureReplacer. See #15730 2022-07-26 23:48:39 +02:00
Henrik Rydgård b529313db2 Slightly improve logging of failed block device reads 2022-07-12 00:11:15 +02:00
Unknown W. Brackets 694e92dc82 Core: Use FileBlockDevice for PBPs without an ISO. 2021-09-06 19:39:34 -07:00
Henrik Rydgård 9480b6672b Loaders: Rename Path() to GetPath().
Path is going to be a struct name.
2021-05-09 17:10:14 -07:00
Unknown W. Brackets 872fecd8ed Io: Allow early cancel of CRC calculation. 2021-02-16 19:37:48 -08:00
Henrik Rydgård 4f43cff5ca Move fileutil, net, image loaders, ui to Common. (#13506)
* Move and rename file_util/fd_util to Common/File/FileUtil and DirListing

Let's also move net while we're at it.

Move the ZIM/PNG loaders over to Common.

Move the UI framework into Common

iOS buildfix

* Buildfix

* Buildfixes

* Apple buildfix

* This typo again..

* UWP buildfix

* Fix build of PPSSPPQt, such as it is (it's not in good condition...)

* Guess what? Another buildfix.
2020-10-04 20:48:47 +02:00
Henrik Rydgård 989e353482 Common.h shouldn't include Log.h.
Buildfixes

More buildfixes. Move JSON code to common.
2020-10-04 11:42:14 +02:00