OSDN Git Service

TextLine.handleRun should throw exception for invalid index
authorSiyamed Sinir <siyamed@google.com>
Fri, 26 Aug 2016 22:23:47 +0000 (15:23 -0700)
committerSiyamed Sinir <siyamed@google.com>
Tue, 30 Aug 2016 21:27:22 +0000 (14:27 -0700)
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

core/java/android/text/TextLine.java

index 2a52961..c411860 100644 (file)
 
 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;