Validate SCE metadata header sizes - #19394
Merged
Merged
Conversation
elad335
requested changes
Sep 3, 2026
| 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 || |
Contributor
There was a problem hiding this comment.
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
force-pushed
the
self-metadata-length-fix
branch
from
September 3, 2026 18:13
3c24d5c to
d13e50b
Compare
Contributor
Author
|
I was only using 1% of my true power. |
elad335
enabled auto-merge (rebase)
September 3, 2026 18:33
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When RPCS3 processes a SCE/SELF file,
SCEDecrypter::LoadMetadataandSELFDecrypter::LoadMetadataread the encrypted metadata info and calculate the remaining metadata-header size fromse_hsizeandse_meta. Those values come from the file header, and the unsigned subtraction happens before validation. A malformed header can therefore turn a too-smallse_hsizeinto a near-maximum vector allocation, aborting file processing before decryption and extraction complete.Validate the fixed metadata prefix, require room for
MetadataHeader, and ensurese_hsizestays within the backing file before allocating. Apply the same guard in both metadata readers.