Skip to content

CFString: fix range in CFStringGetSurrogatePairForLongCharacter#59

Open
DTW-Thalion wants to merge 1 commit into
gnustep:masterfrom
DTW-Thalion:fix/cfstring-surrogate-pair
Open

CFString: fix range in CFStringGetSurrogatePairForLongCharacter#59
DTW-Thalion wants to merge 1 commit into
gnustep:masterfrom
DTW-Thalion:fix/cfstring-surrogate-pair

Conversation

@DTW-Thalion

Copy link
Copy Markdown
Contributor

Summary

CFStringGetSurrogatePairForLongCharacter had an inverted range test:

if (character > 0x10000)
    return false;

A UTF-16 surrogate pair is needed for supplementary-plane characters
(>= U+10000); BMP characters (< U+10000) need none. The old check rejected
almost the entire supplementary plane (U+10001..U+10FFFF) and, conversely,
produced a bogus surrogate pair for BMP characters (and exactly U+10000 was
the only value handled correctly).

Fix

if (character < 0x10000) return false;

Test

Tests/CFString/surrogate.m: U+1F600 yields D83D DE00 and round-trips,
U+10000 yields a pair, and a BMP character (U+0041) yields none.

The function rejected characters greater than U+10000 (returning false)
and produced a surrogate pair for everything up to and including U+10000,
including BMP characters.  The comparison was inverted: a surrogate pair
is needed for supplementary-plane characters (>= U+10000), while BMP
characters (< U+10000) need none, so nearly the whole supplementary
plane (U+10001..U+10FFFF) was wrongly rejected.

Use "character < 0x10000".

Add Tests/CFString/surrogate.m.
@DTW-Thalion DTW-Thalion force-pushed the fix/cfstring-surrogate-pair branch from 02eb6bd to fcf7ff4 Compare July 3, 2026 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant