diff --git a/core/java/android/view/inputmethod/BaseInputConnection.java b/core/java/android/view/inputmethod/BaseInputConnection.java index 739373792047b..6ac16338f6d29 100644 --- a/core/java/android/view/inputmethod/BaseInputConnection.java +++ b/core/java/android/view/inputmethod/BaseInputConnection.java @@ -328,6 +328,11 @@ public class BaseInputConnection implements InputConnection { b = tmp; } + // Guard against the case where the cursor has not been positioned yet. + if (b < 0) { + b = 0; + } + if (b + length > content.length()) { length = content.length() - b; }