@@ -79,6 +79,7 @@ static void TestFlushInternalBuffer(void); /*for improved code coverage in ucnv
79
79
static void TestResetBehaviour (void );
80
80
static void TestTruncated (void );
81
81
static void TestUnicodeSet (void );
82
+ static void TestISO2022Crash (void );
82
83
83
84
static void TestWithBufferSize (int32_t osize , int32_t isize );
84
85
@@ -137,6 +138,7 @@ void addExtraTests(TestNode** root)
137
138
addTest (root , & TestRegressionUTF32 , "tsconv/ncnvtst/TestRegressionUTF32" );
138
139
addTest (root , & TestTruncated , "tsconv/ncnvtst/TestTruncated" );
139
140
addTest (root , & TestUnicodeSet , "tsconv/ncnvtst/TestUnicodeSet" );
141
+ addTest (root , & TestISO2022Crash , "tsconv/ncnvtst/TestISO2022Crash" );
140
142
}
141
143
142
144
/*test surrogate behaviour*/
@@ -2061,3 +2063,32 @@ TestUnicodeSet(void) {
2061
2063
2062
2064
uset_close (set );
2063
2065
}
2066
+
2067
+ // Test for https://unicode-org.atlassian.net/browse/ICU-23165
2068
+ static void TestISO2022Crash (void ) {
2069
+ static const char offendingText [] = {
2070
+ 0x6d , 0x1b , 0x24 , 0x29 , 0x45 , 0x65 , 0x6c , 0x3a ,
2071
+ 0x6c , 0x2e , 0x27 , 0x41 , 0x41 , 0x0e , 0x41 , 0x6c ,
2072
+ };
2073
+ UErrorCode err = U_ZERO_ERROR ;
2074
+ UConverter * cnv = ucnv_open ("ISO_2022,locale=zh,version=2" , & err );
2075
+ if (U_FAILURE (err )) {
2076
+ log_data_err ("Unable to open ISO-2022-CN converter: %s\n" , u_errorName (err ));
2077
+ return ;
2078
+ }
2079
+ ucnv_setToUCallBack (cnv , UCNV_TO_U_CALLBACK_ESCAPE , NULL , NULL , NULL , & err );
2080
+ if (U_FAILURE (err )) {
2081
+ log_data_err ("Unable to setToUCallBack for ISO-2022-CN converter: %s\n" , u_errorName (err ));
2082
+ ucnv_close (cnv );
2083
+ return ;
2084
+ }
2085
+ {
2086
+ UChar toUChars [100 ];
2087
+ UChar * toUCharsPtr = toUChars ;
2088
+ const UChar * toUCharsLimit = toUCharsPtr + 100 ;
2089
+ const char * inCharsPtr = offendingText ;
2090
+ const char * inCharsLimit = offendingText + sizeof (offendingText );
2091
+ ucnv_toUnicode (cnv , & toUCharsPtr , toUCharsLimit , & inCharsPtr , inCharsLimit , NULL , true, & err );
2092
+ }
2093
+ ucnv_close (cnv );
2094
+ }
0 commit comments