TextLine.handleRun should throw exception for invalid index

TextLine.handleRun caused infinite loop if measureLimit is out of bounds
of start and end parameters (for Spannables). For regular String it used
to throw a similar exception in handleText. This CL verifies what is
written in ApiDoc: measureLimit should be between start and limit
inclusive.

Bug: 30985145

Change-Id: I0659e8887f7b43ed2047d08b99bf86d8df80a21c
This commit is contained in:
Siyamed Sinir
2016-08-26 15:23:47 -07:00
parent 885f6495ac
commit 9f3958cc2b

View File

@@ -16,11 +16,9 @@
package android.text;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.FontMetricsInt;
import android.graphics.RectF;
import android.text.Layout.Directions;
import android.text.Layout.TabStops;
import android.text.style.CharacterStyle;
@@ -852,6 +850,11 @@ class TextLine {
int limit, boolean runIsRtl, Canvas c, float x, int top, int y,
int bottom, FontMetricsInt fmi, boolean needWidth) {
if (measureLimit < start || measureLimit > limit) {
throw new IndexOutOfBoundsException("measureLimit (" + measureLimit + ") is out of "
+ "start (" + start + ") and limit (" + limit + ") bounds");
}
// Case of an empty line, make sure we update fmi according to mPaint
if (start == measureLimit) {
TextPaint wp = mWorkPaint;