Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1fb80bbc authored by Siyamed Sinir's avatar Siyamed Sinir
Browse files

Prevent crash for Span change events

For some spans, SpannableStringBuilder cannot determine the previous
start and previous end values correctly. In some cases, previous end
value is smaller than previous start value, and this causes
DynamicLayout to access negative index values. This CL updates
DynamicLayout to reflow from index 0 if such a case occurs.

Test: Added a CTS test
Test: bit CtsTextTestCases:android.text.cts.DynamicLayoutTest#testReflow_afterSpanChangedShouldNotThrowException

Bug: 67926915
Change-Id: Ibc55edfd5e49a7782cdd807e2465f4f21577b68d
parent 6041a4a2
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -1096,6 +1096,11 @@ public class DynamicLayout extends Layout {

        public void onSpanChanged(Spannable s, Object o, int start, int end, int nstart, int nend) {
            if (o instanceof UpdateLayout) {
                if (start > end) {
                    // Bug: 67926915 start cannot be determined, fallback to reflow from start
                    // instead of causing an exception
                    start = 0;
                }
                reflow(s, start, end - start, end - start);
                reflow(s, nstart, nend - nstart, nend - nstart);
            }