diff -ur icu.org/source/common/ubidi.cpp icu/source/common/ubidi.cpp --- icu.org/source/common/ubidi.cpp 2017-03-07 23:57:46.000000000 +0100 +++ icu/source/common/ubidi.cpp 2017-04-21 22:55:11.352659142 +0200 @@ -2125,6 +2125,14 @@ return DirProp_ON; } +static int +isolatesavailable(UBiDi *pBiDi) { + if (pBiDi->isolates == pBiDi->simpleIsolates) { + return pBiDi->isolateCount < SIMPLE_ISOLATES_COUNT-1; + } + return pBiDi->isolateCount < pBiDi->isolatesSize/sizeof(Isolate)-1; +} + static void resolveImplicitLevels(UBiDi *pBiDi, int32_t start, int32_t limit, @@ -2271,7 +2279,7 @@ /* look for the last char not a BN or LRE/RLE/LRO/RLO/PDF */ for(i=limit-1; i>start&&(DIRPROP_FLAG(dirProps[i])&MASK_BN_EXPLICIT); i--); dirProp=dirProps[i]; - if((dirProp==LRI || dirProp==RLI) && limitlength) { + if((dirProp==LRI || dirProp==RLI) && limitlength && isolatesavailable(pBiDi)) { pBiDi->isolateCount++; pBiDi->isolates[pBiDi->isolateCount].stateImp=stateImp; pBiDi->isolates[pBiDi->isolateCount].state=levState.state;