Commit Graph
79 Commits
Author SHA1 Message Date
Henrik RydgårdandClaude Sonnet 5 b322b0621c ReplacedTexture: fix stack OOB write from ZIM mip array contract
LoadZIMPtr() writes width[]/height[]/image[] as arrays (one entry per
mip level, up to ZIM_MAX_MIP_LEVELS) whenever the file has
ZIM_HAS_MIPS set, per its documented contract - but this caller passed
plain scalar locals. A texture-replacement .zim file with that flag
set caused multiple out-of-bounds stack writes. Now passes properly
sized arrays and only uses level 0, matching the existing "we don't
support ZIM mips yet" behavior. Also fixes a pre-existing leak of
image[0] on the "changed since header read" error path.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L4QAoxV2KY7ek4PcZw3WvY
2026-08-09 19:31:02 +02:00
Henrik Rydgård 0049b19fbf Fix OOB in texture replacer mip mixing and non-DXT texture decode
Vuln 17: ReplacedTexture::LoadLevelData let a KTX2/DDS file at a higher
mip level resize the shared data_ vector to its own (attacker-controlled)
mip count, so data_[mipLevel + i] indexed out of bounds and the KTX2
branch resized a different element than it wrote to. Disallow mixing
image formats across mip levels, cap the container mip count, and resize
the same element that is used as the transcode destination.

Vuln 18: DecodeTextureLevel only validated the start address for
non-DXT textures, so guest-controlled w/h/bufw could drive reads past
mapped RAM. Validate the needed range like the DXT path does and clamp
the height; ReadIndexedTex now takes the clamped w/h.
2026-08-01 13:16:22 +02:00
Henrik Rydgård 5e6a051952 Fix path traversal in texture pack filenames; use HasPathTraversal in savestate migration
Texture pack filenames/aliases from textures.ini were used to build read
and write paths with no '..' check, letting a malicious pack read or
write files outside the pack directory.

- LoadIniValues rejects entries with a parent dir component via
  HasParentDirComponent.
- ReplacedTexture::Prepare skips such filenames as defense in depth.
- PSPLoaders savestate migration now uses the shared HasPathTraversal
  helper instead of inline separator checks.
2026-08-01 13:16:22 +02:00
Henrik Rydgård d7c8d6bd80 Clean up cachekey handling in texture replacer 2026-07-18 18:00:51 +02:00
Henrik Rydgård ec6c7b08f5 Add a common TextureAlpha enum, replacing CheckAlphaResult and ReplacedTextureAlpha. 2026-06-09 11:25:50 +02: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 435f523997 Replacement textures: Don't spend frame time waiting for a texture to be finished
It's better to finish rendering the frame and have the texture ready for
the next one, without wasting CPU.

However, if the user set their texture load speed to "Instant", that
means they never want to see any original textures. So in that case, we
do still wait.

Fixes #20519
2025-06-13 23:31:02 +02:00
Henrik Rydgård 252d342cc5 Fix another texture replacement crash (only happens with broken png texture files).
Fix a warning too.
2025-06-10 15:03:15 +02:00
Henrik Rydgård deb2fa4a63 Texture replacement: Fix issue where we could accidentally close a file twice.
Add a sanity check.
2025-06-06 10:31:01 +02:00
Henrik Rydgård 0f18f054ab Make the frame-time budget for uploading replacement textures take framerate into account 2025-04-22 20:19:43 +02:00
Henrik Rydgård df6ed8cfc9 Do some cleanup of #includes in GPU 2024-12-18 13:57:26 +01:00
Henrik Rydgård 839df81852 thread solution: initial progress 2024-12-10 01:27:25 +01:00
Henrik Rydgård 7f13bc1a34 Add new log category for texture replacements 2024-12-01 14:17:01 +01:00
Henrik Rydgård e4c0ed7078 TextureReplacement: Call CloseFile as early as possible when loading textures. 2024-11-30 11:56:27 +01:00
Henrik Rydgård 821624c494 TextureReplacer: Remove a lock that I don't think should be there. Blacklist another folder. 2024-11-30 02:44:01 +01:00
Henrik Rydgård 5eeb15b30a Use Exists instead of GetFileInfo in more cases 2024-11-30 00:39:38 +01:00
Henrik Rydgård 3d31b4ac4c Fix possible framebuffer binding bug in EmuScreen 2024-10-02 16:21:53 +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 3ffcf267cb Allow replacing mip levels of a texture even without a ini file. Probably niche. 2023-12-29 19:06:20 +01:00
Henrik Rydgård ebaebf5945 Merge pull request #18546 from GermanAizek/make-smart-ptr
[Common Data/Core Dialog HLE/GPU Common Vulkan] Optimize create smart pointers using C++17 std::make_*
2023-12-14 14:02:55 +01:00
Herman Semenov 08070e7f31 [Common Data/Core Dialog HLE/GPU Common Vulkan] Optimize create smart pointer using C++17 std::make_* 2023-12-14 15:44:16 +03:00
Herman Semenov de80cc3883 Using reserve if possible 2023-12-12 15:13:43 +03:00
Henrik Rydgård be65cf0fc2 Assert improvements 2023-09-12 17:15:26 +02:00
Henrik Rydgård c1a290b41f ReplacedTexture: Bugfix D3D workaround log check 2023-07-23 22:06:06 +02:00
Henrik Rydgård ace217008a In D3D11, force block compressed textures to have dimensions divisible by 4
Fixes #17745 (crash when loading certain texture packs in D3D11)

This is an old unfortunate limitation. Only applies to the top mip
level, which makes it obvious that it's kinda unnecessary for the
hardware and indeed, Vulkan and OpenGL don't have this limitation.
2023-07-20 19:44:00 +02:00
Henrik Rydgård 2e3a676d71 Support BC1,2,3 formats also if packed in a DX10-style DDS. 2023-05-01 20:55:31 +02:00
Henrik Rydgård cdfe4524ea ReplacedTexture: Opportunistically delete the waitable 2023-03-28 09:21:41 +02:00
Henrik Rydgård 4e41233bb7 Replacement: Save textures even if already replaced, if the png is missing.
Fixes #17182

Not exactly sure what behavior we really want, but I think this one is
OK, and at least more similar to the old one. Now we save
already-replaced textures if the named replacement texture is missing, and there
isn't already a hash-named one in new or the "root".
2023-03-27 15:43:18 +02:00
Unknown W. Brackets f1834fcdde Replacement: Correct padding w/ threads disabled. 2023-03-25 17:12:43 -07:00
Henrik Rydgård 6950801e25 Not much point with a single line cleanup function. Also remove redundant check. 2023-03-19 00:04:48 +01:00
Henrik Rydgård 97c9b9e4f7 Break out PollReplacement from TextureCacheCommon::FindReplacement 2023-03-18 12:01:24 +01:00
Henrik Rydgård 5f76fbe1ad Implement padding-on-copy for compressed textures as well. 2023-03-17 14:00:14 +01:00
Henrik Rydgård 79f4e73110 Replacer: Perform the padding to pow2 size during CopyLevelTo, not during load. Saves memory. 2023-03-17 14:00:14 +01:00
Henrik Rydgård 1b0d5ec3aa Remove a unused state from ReplacedTexture, rename POPULATED to UNLOADED 2023-03-17 00:52:38 +01:00
Henrik Rydgård 6a430f2a14 ReplacedTexture: Some initialization. For UASTC, seems we need to clear the transcoder state. 2023-03-17 00:02:01 +01:00
Henrik Rydgård f154f4a29d Warning fix 2023-03-16 15:06:38 +01:00
Henrik Rydgård e34a5a68de Remove some locking 2023-03-16 12:04:14 +01:00
Henrik Rydgård 725d4195df Small cleanup of purging code 2023-03-16 11:53:39 +01:00
Henrik Rydgård 35f46ec161 Rework the replacement cache. No more duplicate ReplacedTexture objects. 2023-03-16 11:46:05 +01:00
Henrik Rydgård c45376ddc7 Typo fix, thanks iota97 2023-03-15 20:31:27 +01:00
Henrik Rydgård 0fb7ff488e Add a convenient define to experiment with parallel copy 2023-03-15 14:48:32 +01:00
Henrik Rydgård 181ddf8266 Change the API of the old VulkanPushBuffer to match VulkanPushPool. 2023-03-15 09:56:32 +01:00
Henrik Rydgård c31b4be690 Crashfix in ReplacedTexture. Thought I fixed this one before, hm. 2023-03-15 01:23:32 +01:00
Henrik Rydgård 13e63c109f If the target compression format is not supported, just transcode to RGBA8888. 2023-03-14 18:52:42 +01:00
Henrik Rydgård b45f1db005 Correct some error reporting 2023-03-14 18:34:22 +01:00
Henrik Rydgård d8c3269cc6 Fix zipped texture packs (it didn't load the ini from the zip, the rest worked).
Plus a few other things.
2023-03-14 17:53:01 +01:00
Henrik Rydgård 4bbc4c258a Remove sketch of Basis container format support (we go with KTX2 instead as the container) 2023-03-14 14:09:47 +01:00
Henrik Rydgård 6d520d6d6b Vulkan: Enable mobile compressed formats too (oops) 2023-03-14 11:55:21 +01:00
Henrik Rydgård 93bf82a906 Add KTX2 basis/UASTC texture transcoding support 2023-03-14 11:55:21 +01:00
Henrik Rydgård 0fd58d80d5 Detect BASIS files. Doesn't do much with them yet. 2023-03-14 11:55:21 +01:00