Commit Graph
46711 Commits
Author SHA1 Message Date
Henrik Rydgård 32abdd63bf Fix EP-map parsing OOB read in PSMF video stream params
EP_MAP_STRIDE * EPMapEntriesNum was computed in 32-bit and could wrap,
passing the range check while the loop read the unwrapped count; and the
check was skipped entirely when headerOffset == 0 (the player tempbuf
path).

- Use 64-bit math for the EP map size.
- Keep the guest-RAM range check when headerOffset != 0.
- Cap the entry count for the headerOffset == 0 path so the reads stay
  within the player's 64KB tempbuf.
2026-08-01 11:57:27 +02:00
Henrik Rydgård 04d8613d81 Bounds-check charPtr inside PGF::ReadCharGlyph
ReadCharGlyph read glyph metadata at an attacker-controlled bit offset
with no validation, and ReadShadowGlyph only checked after delegating to
it. Validate charPtr (with margin for the header reads) at the top of
ReadCharGlyph so it is safe regardless of caller, and drop the now
redundant checks at the ReadPtr call sites.
2026-08-01 11:57:27 +02:00
Henrik Rydgård 788150c28e Fix out-of-bounds reads in PGF font parsing
PGF::ReadPtr walked four length-prefixed tables and computed table sizes
before any bounds check, and used signed 32-bit size math that could
overflow, allowing a crafted font to read past the input buffer.

- Validate the total size of all tables up front using 64-bit math.
- Check the rev3 extra header fits before reading it.
- Cap charPointerLength/charMapLength/shadowMapLength to avoid absurd
  allocations.
- Bounds-check glyph data offsets before reading each glyph.

Also throw in a warning fix
2026-08-01 11:57:27 +02:00
Henrik Rydgård a8195e7ca6 Clamp HTTP response body to the requested range in HTTPFileLoader
A malicious or MITM'd server could send a Content-Range header matching
the requested range but a larger entity body, overflowing the caller's
fixed-size buffer via output.Take. Clamp the copied size to the requested
range.
2026-08-01 11:57:27 +02:00
Henrik Rydgård 5d10f281ef Fix integer overflow in PMF video frame buffer allocation
pmf_init reported stream dimensions without a cap, and PMFView::Draw
allocated width * height * 4 with 32-bit int arithmetic, so a crafted
ICON1.PMF could overflow the allocation to a small buffer while
sws_scale wrote the full frame.

- Reject videos with dimensions outside 1..720x480 in pmf_init (PMFs on
  the PSP never exceed 720x480).
- Use size_t arithmetic for the frame buffer allocation.
2026-08-01 11:57:27 +02:00
Henrik Rydgård 983068b07a Fix OOB read on unterminated module names in PRX import debug reporter
The import debug reporter used IsValidAddress (start-address only) before
formatting module names with %s, so a crafted unterminated name could be
read past guest RAM. Use IsValidNullTerminatedString instead.
2026-08-01 11:57:27 +02:00
Henrik Rydgård 2100e4ec47 Reject ATRAC files with oversized packets at parse time; honor Verify errors
- InitContextFromTrackInfo now rejects files where sampleSize (from
  blockAlign) exceeds the buffer size, instead of only clamping later in
  DecodeForSas. Keep the DecodeForSas check as defense-in-depth since a
  large buffer could still allow a crafted packet to overflow the fixed
  assembly buffer.
- CChunkFileReader::Verify now returns ERROR_BROKEN_STATE if bounds
  checking fails, so modified savestates are rejected here too.
2026-08-01 11:57:27 +02:00
Henrik Rydgård 398a678b88 Fix null pointer deref in AtracSasAddStreamData
The null check for getAtrac() only logged a warning and fell through to
a virtual call on the null pointer. Return 0 on invalid atrac ID.
2026-08-01 11:57:27 +02:00
Henrik Rydgård 58d4759ceb Add bounds checking to savestate deserialization
PointerWrap tracked no end-of-buffer, so DoState() implementations could
read past the end of a crafted or truncated savestate via DoVoid's
unchecked memcpy, and DoVector could resize to an attacker-controlled
size before reading.

- PointerWrap now tracks a read end; DoVoid/ExpectVoid fail (MODE_NOOP)
  before reading out of bounds.
- String reads are bounds-checked for the whole string including NUL.
- DoVector rejects sizes that can't fit in the remaining buffer.
- LoadPtr takes the buffer size and sets the read end.
- Capping the decompression buffer allocation in LoadFile.
2026-08-01 11:57:24 +02:00
Henrik Rydgård 3ad08377c5 Clamp partial packet copy to main buffer size in Atrac2::DecodeInternal
The loop-with-trailer streaming path copied 'secondBufferByte % sampleSize'
bytes into the main buffer with no clamp. sampleSize is file-derived, so a
crafted value could overflow the destination. Clamp the copy length to
info.bufferByte.
2026-08-01 11:41:24 +02:00
Henrik Rydgård c0f5b3d3ee Skip savestate migration if game ID strings contain a path separator
DISC_ID/DISC_VERSION/homebrewName are attacker-controlled and were used
unsanitized to build migration rename paths. Skip the migration step if
any of them contain a '/' or '\' so the destination can't escape the
savestate directory.
2026-08-01 11:41:24 +02:00
Henrik Rydgård a7b1b319ce Limit PNG decode dimensions to prevent decompression bombs
pngLoadPtr allocated the decoded buffer directly from attacker-controlled
PNG IHDR dimensions with no upper bound, so browsing a crafted game icon
or savedata could trigger a multi-gigabyte allocation.

- Add maxWidth/maxHeight parameters to pngLoadPtr (default 8192x8192)
  and reject images larger than the limits.
- Thread the limits through LoadTextureLevelsFromFileData,
  CreateTextureFromFileData, and CreateTextureFromFile.
- Limit game icons to 256x128 in GameInfoCache and IconCache.
2026-08-01 11:41:24 +02:00
Henrik Rydgård a0fe36f470 Fix mismatched new[]/delete in CachingFileLoader cache eviction
MakeCacheSpaceFor freed cache blocks (allocated with new u8[]) using
scalar delete instead of delete[]. Correct to delete[].
2026-08-01 11:41:24 +02:00
Henrik Rydgård e41a16a6b2 Merge pull request #22008 from hrydgard/vuln-fixes-1
Vulnerability fixes 1/3
2026-07-31 21:18:16 +02:00
Henrik Rydgård 5194382b7b Fix out-of-bounds reads in PARAM.SFO parser
ReadSFO dereferenced index table entries without checking the table fit
within the buffer, and GetDataOffset had no bounds checks at all (reading
attacker-controlled offsets and strcmp'ing without a terminator guard).

- Validate the index table fits entirely within the buffer in ReadSFO.
- Add a size parameter to GetDataOffset and validate the index table,
  key/data table positions, and key string termination before use.
2026-07-31 20:54:17 +02:00
Henrik Rydgård 6d231f3f45 Guard SAS assembly buffer against oversized ATRAC packets
A crafted blockAlign could overflow the fixed 1000-byte assembly stack
buffer in Atrac2::DecodeForSas. Bail out if the packet can't fit.
2026-07-31 20:54:17 +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 f3d7d8bc0c Fix Zip Slip in zip extraction and add unit test
A crafted zip with a parent-directory ("..") entry name could escape the
destination directory during extraction, writing arbitrary files on the
host (e.g. into startup/autostart folders). ExtractZipContents built the
output path by concatenating the raw zip entry name onto the destination
with no traversal check.

Changes:
- Add HasParentDirComponent() utility in Core/Util/PathUtil and use it in
  GameManager::ExtractZipContents to reject entries with a ".." component.
  Guard both the directory-creation and file-writing passes.
- Expose ExtractZipContents as public for testing.
- Add unittest/TestZipSlip which crafts a zip with a "../evil.txt" entry
  and verifies it is not written outside the destination directory.
2026-07-31 20:35:12 +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 135f59617f Add instructions for running the C++ unit tests to AGENTS.md
The /unittest subdirectory contains a separate binary with C++ unit tests
alongside the pspautotests runner. Document how to build and run them
(UnitTest.exe on Windows, PPSSPPUnitTest on Linux/Mac), and that they
should be run after substantial changes at the end of a chunk of work.
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 d90fdee8fc Merge pull request #22006 from hrydgard/assorted-ui-fixes
UI event processing fixes
2026-07-30 21:45:31 +02:00
Henrik Rydgård edce05211e Add more logging in onPause 2026-07-30 18:50:32 +02:00
Henrik Rydgård ecce9baffa Fix some pause screen issues 2026-07-30 18:44:44 +02:00
Henrik Rydgård cab9a4fcd7 Remove obsolete code 2026-07-30 18:27:38 +02:00
Henrik Rydgård f94c094441 Fix problematic change in event processing ordering 2026-07-30 18:27:09 +02:00
Henrik Rydgård d6e0308c11 Merge pull request #21990 from Arkadyzja/savestate-compact-blockallocator
Savestate: compact BlockAllocator serialization (section v2)
2026-07-30 17:23:25 +02:00
Henrik Rydgård e3975c7aae Merge pull request #21988 from Arkadyzja/savestate-forget-stale-helper-threads
Savestate: don't let stale HLE helper threads mutate restored kernel state
2026-07-30 17:21:54 +02:00
Henrik Rydgård 820d420f47 Merge pull request #21989 from Arkadyzja/savestate-compact-audio-queues
Savestate: store only live audio queue data (AudioChannel section v3)
2026-07-30 17:20:30 +02:00
Henrik Rydgård 322fe59596 Merge pull request #21987 from Arkadyzja/savedialog-serialize-iothreadstatus
Savedata dialog: serialize ioThreadStatus (bump section to v3)
2026-07-30 17:02:51 +02:00
Henrik Rydgård 3a56d4d53e Merge pull request #22005 from hrydgard/low-precision-float-check
OpenGL: Check for support for high precision float in fragment shaders, and avoid the new workarounds if not supported
2026-07-30 11:08:45 +02:00
Henrik Rydgård 10a5d2f810 OpenGL: Improve checks for fragment shader float precision.
Fixes #22001 (although there may be other artifacts).
2026-07-30 10:03:15 +02:00
Henrik Rydgård 683704d61d Add new log category for config 2026-07-30 10:03:15 +02:00
Henrik Rydgård e69f727f9a Merge pull request #22002 from hrydgard/ai-autotest-workflow
AI pspautotests workflow description, and a few fixes that came out of it. Plus some manual sceReg implementation
2026-07-30 10:01:51 +02:00
Henrik Rydgård ebfd1d755f Bump the tests, fixing the tls test and also the timezone conversion 2026-07-30 01:34:46 +02:00
Henrik Rydgård c7653e6b7f Improve sceReg and its tests 2026-07-30 00:26:10 +02:00
Henrik Rydgård e9a0e54e92 sceRtc: Deepseek's implementation of parsing various date formats 2026-07-29 23:41:29 +02:00
Henrik Rydgård c8093171a5 Use the new AI workflow to have DeepSeek figure out an ancient problem with mailbox tests 2026-07-29 23:04:44 +02:00
Henrik Rydgård 4ecbb8b580 Teach the AI to use pspautotests to fix bugs in PPSSPP (it refined its own instructions) 2026-07-29 22:37:21 +02:00
Henrik Rydgård 5dceea4251 Merge pull request #22000 from hrydgard/debugger-improvements
Turn off "Ignore bad memory accesses" in headless
2026-07-29 22:11:12 +02:00
Henrik Rydgård 2b509e4b1e Minor cleanups, revert change in sceKernelMbx 2026-07-29 20:30:17 +02:00
Henrik Rydgård d6b33ba58d test.py comments 2026-07-29 19:49:17 +02:00
Henrik Rydgård e0ddfc7109 Add --print-equal-lines option to headless, good for context when looking at output 2026-07-29 18:55:00 +02:00
Henrik Rydgård c99a303646 Fix behavior so we can turn off "IgnoreBadMemAccess" in headless 2026-07-29 18:38:25 +02:00
Henrik Rydgård cc57945280 Made the threads/mbx/refer/refer test not crash 2026-07-29 16:27:51 +02:00
Henrik Rydgård 54618c67c6 Headless improvements 2026-07-29 16:27:33 +02:00
Henrik Rydgård 35355d90e2 Merge pull request #21999 from hrydgard/vr-shader-fix
VR fixes
2026-07-29 15:47:13 +02:00
Henrik Rydgård baf200acec OpenXR: Improve mouse emulation, fix scrolling 2026-07-29 15:20:11 +02:00
Henrik Rydgård b46566adc2 Logging improvements 2026-07-29 14:42:24 +02:00
Henrik Rydgård 6bdaf7caee Fix null pointer access in InfraredHelper.java 2026-07-29 14:40:53 +02:00