Bug 1240500 - Early return on empty pattern to avoid an infinte loop and OOM r=rnewman

MozReview-Commit-ID: 7GlsZjfmE0y
This commit is contained in:
Andrzej Hunt 2016-02-25 15:28:08 -08:00
parent d5efa2bb5f
commit 9136800123

View File

@ -25,6 +25,7 @@ import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.graphics.Typeface;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.text.style.StyleSpan;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
@ -170,7 +171,15 @@ class SearchEngineRow extends AnimatedHeightLayout {
*/
private void refreshOccurrencesWith(String pattern, String string) {
mOccurrences.clear();
// Don't try to search for an empty string - String.indexOf will return 0, which would result
// in us iterating with lastIndexOfMatch = 0, which eventually results in an OOM.
if (TextUtils.isEmpty(pattern)) {
return;
}
final int patternLength = pattern.length();
int indexOfMatch = 0;
int lastIndexOfMatch = 0;
while(indexOfMatch != -1) {