From 9f3958cc2ba3da1406caac64650620d226bf8562 Mon Sep 17 00:00:00 2001 From: Siyamed Sinir Date: Fri, 26 Aug 2016 15:23:47 -0700 Subject: [PATCH] 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 --- core/java/android/text/TextLine.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/java/android/text/TextLine.java b/core/java/android/text/TextLine.java index 2a52961984f7..c4118605b44c 100644 --- a/core/java/android/text/TextLine.java +++ b/core/java/android/text/TextLine.java @@ -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; -- 2.11.0