Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] ArgumentOutOfRangeException crash on Android in TextBlockExtensions.RecalculateSpanPositions #15811

Open
holecekp opened this issue Aug 29, 2023 · 1 comment
Labels
a/label p/Android s/unverified New report that has yet to be verified t/bug 🐛

Comments

@holecekp
Copy link

Description

AppCenter reports a few crashes on Android in TextBlockExtensions.RecalculateSpanPositions after updating to Xamarin.Forms 5.0.0.2612 with the following exception:

System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
  at System.Collections.Generic.List`1[T].get_Item (System.Int32 index) [0x00009] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Collections/Generic/List.cs:161
  at System.Collections.ObjectModel.Collection`1[T].get_Item (System.Int32 index) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Collections/ObjectModel/Collection.cs:46
  at Xamarin.Forms.Platform.Android.TextViewExtensions.RecalculateSpanPositions (Android.Widget.TextView textView, Xamarin.Forms.Label element, Android.Text.SpannableString spannableString, Xamarin.Forms.SizeRequest finalSize) [0x000d4] in D:\a\1\s\Xamarin.Forms.Platform.Android\Extensions\TextViewExtensions.cs:104
  at Xamarin.Forms.Platform.Android.FastRenderers.LabelAppCompatRenderer.OnLayout (System.Boolean changed, System.Int32 left, System.Int32 top, System.Int32 right, System.Int32 bottom) [0x0002e] in D:\a\1\s\Xamarin.Forms.Platform.Android\FastRenderers\LabelAppCompatRenderer.cs:161
  at Android.Views.View.n_OnLayout_ZIIII (System.IntPtr jnienv, System.IntPtr native__this, System.Boolean changed, System.Int32 left, System.Int32 top, System.Int32 right, System.Int32 bottom) [0x00008] in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-33/mcw/Android.Views.View.cs:18964
  at (wrapper delegate-invoke) <Module>.invoke_void_intptr_intptr_bool_int_int_int_int(intptr,intptr,bool,int,int,int,int)
  at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPZIIII_V (_JniMarshal_PPZIIII_V callback, System.IntPtr jnienv, System.IntPtr klazz, System.Boolean p0, System.Int32 p1, System.Int32 p2, System.Int32 p3, System.Int32 p4) [0x00005] in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:429

I am including a symbolicated stack trace with line numbers. A kind of similar exception used to happen occasionally on UWP with on a different line in the same method (#15732), but it worked well on Android until now. Both old version (without the issue) and the new version (with the issue and the newer Xamarin.Forms) targets Android 13.

RecalculateSpanPositions method accesses items in various collections without checking if the index is in the correct range (element.FormattedText.Spans[count] in case of this crash, where count is limited by spannableString.Length() not by the number of the items of FormattedText.Spans). Would it be possible to add the checks on these places so that the app would not crash at least?

Steps to Reproduce

Cannot be reproduced. I have just reports from AppCenter.Crashes.

Expected Behavior

No crashes

Actual Behavior

Crashes

Basic Information

  • Version with issue: 5.0.0.2612
  • Last known good version: 5.0.0.2578
  • Platform Target Frameworks:
    • Android: 13
  • NuGet Packages: Xamarin.Forms, Xamarin.Essentials, Xamarin.CommunityToolkit, Microsoft.AppCenter.Crashes, System.Text.Json, sqlite-net-pcl, Xamarin.AndroidX.Core.SplashScreen.

Environment

Show/Hide Visual Studio info
Microsoft Visual Studio Community 2022
Version 17.7.2
VisualStudio.17.Release/17.7.2+34018.315
Microsoft .NET Framework
Version 4.8.04084

Installed Version: Community

Visual C++ 2022   00482-90000-00000-AA019
Microsoft Visual C++ 2022

ASP.NET and Web Tools   17.7.271.4230
ASP.NET and Web Tools

Azure App Service Tools v3.0.0   17.7.271.4230
Azure App Service Tools v3.0.0

Azure Functions and Web Jobs Tools   17.7.271.4230
Azure Functions and Web Jobs Tools

C# Tools   4.7.0-3.23416.8+43b0b05cc4f492fd5de00f6f6717409091df8daa
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Extensibility Message Bus   1.4.34 (main@d5ab18b)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Mono Debugging for Visual Studio   17.7.27 (547ea6f)
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager   6.7.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Razor (ASP.NET Core)   17.7.3.2333001+0ab18affdf2a37647768d0e25f5f021bee6257a1
Provides languages services for ASP.NET Core Razor.

SQL Server Data Tools   17.7.9.2
Microsoft SQL Server Data Tools

Test Adapter for Boost.Test   1.0
Enables Visual Studio's testing tools with unit tests written for Boost.Test.  The use terms and Third Party Notices are available in the extension installation directory.

Test Adapter for Google Test   1.0
Enables Visual Studio's testing tools with unit tests written for Google Test.  The use terms and Third Party Notices are available in the extension installation directory.

TypeScript Tools   17.0.20628.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   4.7.0-3.23416.8+43b0b05cc4f492fd5de00f6f6717409091df8daa
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools   17.7.0-beta.23314.10+e612cf93b989503c89e3a5830090062b7ab5e143
Microsoft Visual F# Tools

Visual Studio IntelliCode   2.2
AI-assisted development for Visual Studio.

VisualStudio.DeviceLog   1.0
Information about my package

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

VSPackage Extension   1.0
VSPackage Visual Studio Extension Detailed Info

Xamarin   17.7.0.215 (d17-7@30b1e9b)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer   17.7.3.9 (remotes/origin/d17-7@796d191def)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates   17.7.21 (150ec9f)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK   13.2.1.2 (d17-5/a8a26c7)
Xamarin.Android Reference Assemblies and MSBuild support.
    Mono: d9a6e87
    Java.Interop: xamarin/java.interop/d17-5@149d70fe
    SQLite: xamarin/sqlite/3.40.1@68c69d8
    Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-5@ca1552d


Xamarin.iOS and Xamarin.Mac SDK   16.4.0.5 (191fe02ea)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.
@holecekp holecekp added s/unverified New report that has yet to be verified t/bug 🐛 labels Aug 29, 2023
@xleon
Copy link

xleon commented Sep 22, 2023

Same thing here.
All of our UI tests passed correctly, but this is happening in prod in HTC and Huawei devices.

image

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/label p/Android s/unverified New report that has yet to be verified t/bug 🐛
Projects
None yet
Development

No branches or pull requests

3 participants