Skip to content

Validate SCE metadata header sizes - #19394

Merged
elad335 merged 2 commits into
RPCS3:masterfrom
acts-1631:self-metadata-length-fix
Sep 3, 2026
Merged

Validate SCE metadata header sizes#19394
elad335 merged 2 commits into
RPCS3:masterfrom
acts-1631:self-metadata-length-fix

Conversation

@acts-1631

Copy link
Copy Markdown
Contributor

When RPCS3 processes a SCE/SELF file, SCEDecrypter::LoadMetadata and SELFDecrypter::LoadMetadata read the encrypted metadata info and calculate the remaining metadata-header size from se_hsize and se_meta. Those values come from the file header, and the unsigned subtraction happens before validation. A malformed header can therefore turn a too-small se_hsize into a near-maximum vector allocation, aborting file processing before decryption and extraction complete.

Validate the fixed metadata prefix, require room for MetadataHeader, and ensure se_hsize stays within the backing file before allocating. Apply the same guard in both metadata readers.

@AniLeo
AniLeo requested review from Megamouse and elad335 September 3, 2026 13:14
Comment thread rpcs3/Crypto/unself.cpp Outdated
std::vector<u8> metadata_headers(sce_hdr.se_hsize - (sizeof(sce_hdr) + sce_hdr.se_meta + sizeof(meta_info)));
const u64 metadata_headers_offset = sizeof(sce_hdr) + sce_hdr.se_meta + sizeof(meta_info);

if (sce_hdr.se_hsize < metadata_headers_offset ||

@elad335 elad335 Sep 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not rely on overflow to check for overflow. An alternative solution is:

Suggested change
if (sce_hdr.se_hsize < metadata_headers_offset ||
constexpr usz sizeof_meta_and_header = sizeof(meta_info) + sizeof(sce_hdr);
if (sce_hdr.se_meta > usz{umax} - sizeof_meta_and_header ||
sce_hdr.se_hsize < sizeof_meta_and_header + sce_hdr.se_meta ||

This also protects against se_meta addition from overflow.

@acts-1631
acts-1631 force-pushed the self-metadata-length-fix branch from 3c24d5c to d13e50b Compare September 3, 2026 18:13
@acts-1631

Copy link
Copy Markdown
Contributor Author

I was only using 1% of my true power.

@elad335
elad335 enabled auto-merge (rebase) September 3, 2026 18:33
@elad335
elad335 merged commit 645458b into RPCS3:master Sep 3, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants