Index: Bidi.java =================================================================== --- Bidi.java (revision 428277) +++ Bidi.java (working copy) @@ -132,6 +132,15 @@ */ public Bidi(char[] text, int textStart, byte[] embeddings, int embStart, int paragraphLength, int flags) { + if (textStart < 0) { + throw new IllegalArgumentException("Negative textStart value " + textStart); + } + if (embStart < 0) { + throw new IllegalArgumentException("Negative embStart value " + embStart); + } + if (paragraphLength < 0) { + throw new IllegalArgumentException("Negative paragraph length " + paragraphLength); + } long pBidi = createUBiDi(text, textStart, embeddings, embStart, paragraphLength, flags); readBidiInfo(pBidi); @@ -167,29 +176,31 @@ byte[] realEmbeddings = null; - if (text == null || text.length < textStart + paragraphLength) { + if (text == null || text.length - textStart< paragraphLength) { throw new IllegalArgumentException(); } realText = new char[paragraphLength]; System.arraycopy(text, textStart, realText, 0, paragraphLength); if (embeddings != null) { - if (embeddings.length < embStart + paragraphLength) { + if (embeddings.length - embStart < paragraphLength) { throw new IllegalArgumentException(); } - Bidi temp = new Bidi(text, textStart, null, 0, paragraphLength, - flags); - realEmbeddings = new byte[paragraphLength]; - System.arraycopy(temp.offsetLevel, 0, realEmbeddings, 0, - paragraphLength); - for (int i = 0; i < paragraphLength; i++) { - byte e = embeddings[i]; - if (e < 0) { - realEmbeddings[i] = (byte) (BidiWrapper.UBIDI_LEVEL_OVERRIDE - e); - } else if (e > 0) { - realEmbeddings[i] = e; - } else { - realEmbeddings[i] |= (byte) BidiWrapper.UBIDI_LEVEL_OVERRIDE; + if (paragraphLength > 0) { + Bidi temp = new Bidi(text, textStart, null, 0, paragraphLength, + flags); + realEmbeddings = new byte[paragraphLength]; + System.arraycopy(temp.offsetLevel, 0, realEmbeddings, 0, + paragraphLength); + for (int i = 0; i < paragraphLength; i++) { + byte e = embeddings[i]; + if (e < 0) { + realEmbeddings[i] = (byte) (BidiWrapper.UBIDI_LEVEL_OVERRIDE - e); + } else if (e > 0) { + realEmbeddings[i] = e; + } else { + realEmbeddings[i] |= (byte) BidiWrapper.UBIDI_LEVEL_OVERRIDE; + } } } }