Disallow creation of CFStrings from non-8bit c-strings #5165
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.
It is invalid to create a
CFString
from a c-string of a non-8bit encoding. Encodings that are not 8bit encodings may have embedded null bytes that represent a portion of a scalar (for example, the leading byte of an ASCII scalar represented in UTF-16) which means these encodings are not suitable for c-string representation. Currently, we do not enforce this and creation can sometimes fail, sometimes truncate the provided text, and other times create a malformedCFString
which may behave unexpectedly when callingCFStringGetCStringPtr
on it (it can vend a pointer of the wrong encoding). This change enforces this requirement by trapping at runtime if an invalid encoding is provided.I left some comments in
CFStringGetCStringPtr
about the potentially confusing behavior that previous arose here due to this issue with an explanation about how the enforcement at string creation time makes the logic in that function sound.Resolves #5164