Fix a crash in Unreal Engine games when system language is Chinese#182
Merged
XuYicong merged 1 commit intoPlayCover:masterfrom Apr 16, 2025
Merged
Fix a crash in Unreal Engine games when system language is Chinese#182XuYicong merged 1 commit intoPlayCover:masterfrom
XuYicong merged 1 commit intoPlayCover:masterfrom
Conversation
This was referenced Jan 29, 2025
Contributor
Author
|
also related: PlayCover/PlayCover#1755 |
This was
linked to
issues
Jan 31, 2025
Contributor
Author
|
I have submitted the new codes. Compared to the previous version, now |
XuYicong
approved these changes
Apr 15, 2025
TheMoonThatRises
approved these changes
Apr 15, 2025
1 task
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.
Summary
Recently some Unreal Engine games started using the Extended Virtual Addressing feature. When this feature is enabled, Unreal Engine attempts to extract the Entitlement from the executable and checks whether it contains
com.apple.developer.kernel.extended-virtual-addressing.However, due to an issue in Unreal Engine’s code, it read 8 extra bytes. These extra bytes cause a string decoding failure when the system language is set to Chinese, ultimately leading to a crash.
Explanations
FApplePlatformMemory.cpp
This function calls
FIOSPlatformMisc::IsEntitlementEnabled.FIOSPlatformMisc.cpp
EntitlementsData()returns an empty string, but therangeis nonzero, causing stringByReplacingOccurrencesOfString to crash with a Range out of bounds error.IOSPlatformMisc.cpp
It reads 8 extra bytes, which causes a decoding failure and returns an empty string.
Why has it read 8 extra bytes?
The
blob.lengthrepresents the total length ofCS_GenericBlob, not thedataarray.The actual length of the data array should be blob.length - 8 bytes.
Why does it return an empty string?
Expected data:
<plist>...</plist>Actual data read:
<plist>...</plist>\xfa\xde\x71\x72When we pass the data to stringWithFormat, it uses the encoding returned by
CFStringGetSystemEncoding()to decode it. When the system language is set to Chinese, it will useCFStringEncodingMacChineseSimp, but the decoding fails, returning an empty string.Why doesn’t the crash happen on iOS?
On iOS,
CFStringGetSystemEncoding()always returns0regardless of the system language, so it works fine. On macOS,CFStringGetSystemEncoding()returns different values depending on the system language.How to Fix
Hook the string replacement function. If the source string is empty, return immediately to prevent a Range out of bounds error.