Debug apps abort at startup when a debug.mono.env entry is 50+ characters (strings.hh ensure_have_extra)
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- Nửa ngày
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
Start in src/native/mono/monodroid/monodroid-glue.cc at MonodroidRuntime::set_debug_env_vars (around lines 1010-1020), where each |-separated token is copied into a static_local_string sized by SMALL_STRING_PARSE_BUFFER_LEN, defined in monodroid-glue-internal.hh line 73. Reproduce by setting debug.mono.env to a 50+ character entry on a Debug build and confirm the abort. Done means a long entry no longer aborts the process, for example by using a dynamic string buffer or logging a warning, and the app still starts.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Android framework version
net10.0-android
Affected platform version
.NET SDK 10.0.401, Microsoft.Android.Sdk 36.1.69 (Mono runtime, Debug configuration)
Description
In a Debug build, if the debug.mono.env system property contains a |-separated entry that is 50 characters or longer, the app aborts at startup, before any managed code runs:
F monodroid: Attempt to store too much data in a buffer (capacity: 61; exceeded by: 1)
F monodroid: Abort at strings.hh:908:5 ('void xamarin::android::string_base<50, xamarin::android::static_local_storage<50>>::ensure_have_extra(size_t) ...')
F libc : Fatal signal 6 (SIGABRT)
This looks exactly like an app crash. The system property is device-wide and survives uninstall/reinstall, so every Debug .NET Android app on the device keeps dying until the property is cleared.
Root cause (confirmed by code inspection, release/10.0.1xx @ 7d6e309): MonodroidRuntime::set_debug_env_vars splits the property on | and copies each token into a fixed-size buffer:
static_local_string<SMALL_STRING_PARSE_BUFFER_LEN> arg (arg_token.length ());
arg.assign (arg_token.start (), arg_token.length ());
- https://github.com/dotnet/android/blob/7d6e309920313db622262491e482858125a0417b/src/native/mono/monodroid/monodroid-glue.cc#L1010-L1020
SMALL_STRING_PARSE_BUFFER_LEN = 50: https://github.com/dotnet/android/blob/7d6e309920313db622262491e482858125a0417b/src/native/mono/monodroid/monodroid-glue-internal.hh#L73
A static_local_string never grows, and assign needs length + 1 bytes (NUL terminator). Any token of 50 or more characters trips ensure_have_extra and aborts the process. The reported "capacity" equals the token length because the buffer is sized to max(50, length), which makes the abort message look nonsensical.
I could not find the equivalent code on current main (CoreCLR host), so this seems specific to the Mono runtime.
Steps to Reproduce
Tested on an x86_64 Android 15 emulator (API 35), with the template app:
dotnet new android -n MonoEnvRepro && cd MonoEnvRepro- Build and install the Debug configuration on the emulator:
dotnet build -c Debug -t:Install - Launch it, and confirm it starts (
adb shell pidof com.companyname.MonoEnvReproreturns a pid). - Set the property to a value with a 50+ character entry:
adb shell "setprop debug.mono.env 'CALC_DIAG_DIR=/data/user/0/some.app/files/diagnostics'" - Force-stop and relaunch the app. It aborts immediately with the log above, and
pidofreturns nothing. - Uninstall and reinstall the app. It still aborts.
Measured threshold (value = K=aaaa... of the given length, single entry): lengths 20, 40, 48 and 49 start fine; lengths 50, 51, 52 and 56 abort. A short value like X=1, and a value with several short entries joined by | (76 chars total, each entry under 50), start fine.
Did you find any workaround?
- Keep every
|-separated entry under 50 characters, for example by using short paths. - To recover a device that is stuck, clear the property with an empty value:
adb shell 'setprop debug.mono.env ""'. Other "empty-looking" values such as''did not clear it.
Relevant log output
F monodroid: Attempt to store too much data in a buffer (capacity: 61; exceeded by: 1)
F monodroid: Abort at strings.hh:908:5 ('void xamarin::android::string_base<50, xamarin::android::static_local_storage<50>>::ensure_have_extra(size_t) [MaxStackSize = 50, TStorage = xamarin::android::static_local_storage<50>, TChar = char]')
F libc : Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 4286 (me.MonoEnvRepro), pid 4286 (me.MonoEnvRepro)
Suggested fix: use a dynamic_local_string (or size the buffer from the token) for arg in set_debug_env_vars, and/or log a warning instead of aborting on an over-long entry.
- Ngôn ngữ chính
- C#
- Star
- 2.1k
- Fork
- 581
- Merge trung bình
- 2 ngày 6 phút
- Pull request đã merge (30 ngày)
- 245
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của dotnet/android
-
Area: App+Library Build
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
EditText.getText() isn't boundĐang mởArea: Mono.Android
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
dotnet/android#9192 · 4 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
.NET 11 RC2 MAUI app fails to compile (NativeAOT) with MAUI Community ToolkitCó thể đã có người làm @simonrozsival đã nhận hôm nay. Đang mởArea: App+Library Build needs-triage
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 15/100
dotnet/android#13143 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
needs-triage
Độ khó 4/5 Hơn một tuần Mức phù hợp với người mới 18/100
Maintainer thường phản hồi trong vòng 1 ngày
-
_Microsoft.Android.Resource.Designer.dll carries the build's wall-clock time as its PE TimeDateStamp, so Release builds are not reproducible (GenerateResourceDesignerAssembly passes no WriterParameters.Timestamp)Có thể đã có người làm @jonathanpeppers đã nhận 1 ngày trước. Đang mởneeds-triage
dotnet/android#13140 · 1 bình luận · 1 reaction · 2 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của dotnet/android
Issue tương tự
-
AzureBlobSnapshotStore.LoadAsync allocates the snapshot twice (growable MemoryStream + ToArray)Đang mởenhancement
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 72/100
-
bug ui-only
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
ClickHouse/clickhouse-cs#689 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 7 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 65/100
vchelaru/FlatRedBall2#1481 ·
Maintainer thường phản hồi trong vòng 1 ngày