ICU-22635 Avoid integer-overflow for invalid large UChar32

This commit is contained in:
Frank Tang 2024-01-17 17:26:00 -08:00 committed by Frank Yung-Fong Tang
parent 8f80c62aa2
commit e1415d1282
2 changed files with 11 additions and 3 deletions

View file

@ -1390,8 +1390,11 @@ Normalizer2Impl::composePair(UChar32 a, UChar32 b) const {
} else if(norm16<minYesNoMappingsOnly) {
// a combines forward.
if(isJamoL(norm16)) {
if (b < Hangul::JAMO_V_BASE) {
return U_SENTINEL;
}
b-=Hangul::JAMO_V_BASE;
if(0<=b && b<Hangul::JAMO_V_COUNT) {
if(b<Hangul::JAMO_V_COUNT) {
return
(Hangul::HANGUL_BASE+
((a-Hangul::JAMO_L_BASE)*Hangul::JAMO_V_COUNT+b)*
@ -1400,8 +1403,11 @@ Normalizer2Impl::composePair(UChar32 a, UChar32 b) const {
return U_SENTINEL;
}
} else if(isHangulLV(norm16)) {
if (b <= Hangul::JAMO_T_BASE) {
return U_SENTINEL;
}
b-=Hangul::JAMO_T_BASE;
if(0<b && b<Hangul::JAMO_T_COUNT) { // not b==0!
if(b<Hangul::JAMO_T_COUNT) { // not b==0!
return a+b;
} else {
return U_SENTINEL;

View file

@ -1210,7 +1210,9 @@ BasicNormalizerTest::TestCompare() {
if( nfcNorm2->composePair(0x20, 0x301)>=0 ||
nfcNorm2->composePair(0x61, 0x305)>=0 ||
nfcNorm2->composePair(0x1100, 0x1160)>=0 ||
nfcNorm2->composePair(0xac00, 0x11a7)>=0
nfcNorm2->composePair(0xac00, 0x11a7)>=0 ||
nfcNorm2->composePair(0x1100, 0x80000020)>= 0 || // ICU-22635
nfcNorm2->composePair(0xac00, 0x80000020)>= 0 // ICU-22635
) {
errln("NFC.composePair() incorrectly composes some pairs of characters");
}