[iOS][CoreCLR] SIGSEGV in CFNumberGetValue from MacProxy: CFNumberType is passed as 32-bit, but the native type is CFIndex
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 78/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- csharp, ios
- Área
- mobile-dev, networking
Línea de trabajo
Comienza con src/libraries/Common/src/Interop/OSX/Interop.CoreFoundation.CFNumber.cs y compara su declaración con CFNumber.h. Sigue la ruta de MacProxy utilizada por SocketsHttpHandler y reproduce el problema con una configuración de proxy HTTP/HTTPS o PAC en iOS. La tarea está terminada cuando la resolución del proxy ya no se bloquea y la solicitud continúa como lo hace en .NET 10.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Description
On .NET 11 RC1 with CoreCLR, iOS apps crash with EXC_BAD_ACCESS (SIGSEGV) in CFNumberGetValue when SocketsHttpHandler asks HttpClient.DefaultProxy (MacProxy) for a proxy and the system configuration returns an HTTP/HTTPS proxy. The proxy can come from a PAC script or a manual proxy setting. We hit it on every launch on real devices behind a PAC proxy, about half a second after startup. More specifically, in our case we were testing our app migrating from .NET 10 to .NET 11 in Browserstack, which has a proxy.
The cause is the P/Invoke declaration in src/libraries/Common/src/Interop/OSX/Interop.CoreFoundation.CFNumber.cs:
internal enum CFNumberType { kCFNumberIntType = 9 } // int-sized
[LibraryImport(Libraries.CoreFoundationLibrary)]
private static unsafe partial int CFNumberGetValue(IntPtr handle, CFNumberType type, int* value);
Natively, CFNumberType is 64-bit (CFNumber.h):
typedef CF_ENUM(CFIndex, CFNumberType) { ... kCFNumberIntType = 9, ... };
Boolean CFNumberGetValue(CFNumberRef number, CFNumberType theType, void *valuePtr);
The managed side passes only 32 bits, so the upper half of x1 is unspecified. CFNumberGetValue uses the whole register as an index into its type table and reads far out of bounds.
The declaration has looked like this since MacProxy was written. JIT and AOT code happen to zero-extend 32-bit values, so the bug stayed hidden. The CoreCLR interpreter passes native-call arguments from 8-byte stack slots whose upper half can still hold stale data, and that exposes it.
Reproduction Steps
In an app:
- Create a net11.0-ios app. CoreCLR is the default runtime.
- At startup, make a request through
SocketsHttpHandler:
using var client = new HttpClient(new SocketsHttpHandler());
await client.GetAsync("https://example.com/");
IHttpClientFactoryclients useSocketsHttpHandlerby default, so they do this too.
Run the app on an iOS device whose Wi-Fi uses a proxy.- We use Automatic proxy configuration with a PAC URL. A PAC file that returns a proxy is enough, for example
function FindProxyForURL(url, host) { return "PROXY 10.0.0.1:8080"; }. - The proxy doesn't have to exist. The crash happens while the proxy URI is being built, before any connection is made.
- A PAC script that returns DIRECT does not crash, because no port is read.
- We use Automatic proxy configuration with a PAC URL. A PAC file that returns a proxy is enough, for example
- The app crashes about half a second after launch.
Expected behavior
The proxy is resolved (for the PAC example above, http://10.0.0.1:8080/) and the request continues. That's what happens on .NET 10 (Mono) and with CoreCLR on Android and macOS.
Actual behavior
The process terminates with a segmentation fault in CFNumberGetValue.
Device crash report (iPhone 16, iOS 18.6):
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x000000059dd335c2
Termination: Segmentation fault: 11 (namespace SIGNAL, code 11), by exc handler
Triggered by Thread: 17 (name: ".NET TP Worker")
0 CoreFoundation + 0x224c (CFNumberGetValue + 192)
1 libcoreclr + 0x328bdc
2 libcoreclr + 0x28d9c8
3 libcoreclr + 0x290658
4 libcoreclr + 0x1fbd8c
5 libcoreclr + 0x3275d8
6 libcoreclr + 0x328ab0
7 libcoreclr + 0x28e1c4
8 libcoreclr + 0x292260
9 libcoreclr + 0x1fbd8c
10 libcoreclr + 0x3275d8
11 CFNetwork + 0x1a59ac (PAC::rlsPerform(void*) + 80)
12 CoreFoundation + 0xf92c (__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28)
...
16 CoreFoundation + 0x11adc (CFRunLoopRunSpecific + 572)
17 libcoreclr + 0x328bdc
... (interpreted MacProxy / SocketsHttpHandler frames on a thread-pool worker)
| Register | Value | Meaning |
|---|---|---|
| 0x | 0x9cfc0aa3eede9a4b | A valid tagged-pointer CFNumber (bit 63 set) |
| 0x1 | 0x0000000200000009 | kCFNumberIntType (9), with stale 0x2 in the upper 32 bits |
| 0x2 | 0x0000000126500858 | &value, on the interpreter stack |
The fault address is exactly the type table plus 2 × x1. The table is at CoreFoundation + 0x21d5b0 (base 0x19db16000), and 0x19dd335b0 + 2 × 0x200000009 = 0x59dd335c2.
The same crash on the iOS simulator with the RC1 iossimulator-arm64 runtime pack gives a symbolicated version of the device stack above, frame for frame. It faults at x1 = 0x100000009 and 0x3805e4312:
CoreFoundation CFNumberGetValue
libcoreclr CallJittedMethodRetI8
libcoreclr InvokeUnmanagedMethodWithTransition
libcoreclr InterpExecMethod
libcoreclr ExecuteInterpretedMethod
libcoreclr InterpreterStubRetVoid
libcoreclr CallJittedMethodRetVoid
libcoreclr InvokeCalliStub
libcoreclr InterpExecMethod
libcoreclr ExecuteInterpretedMethod
libcoreclr InterpreterStubRetVoid
CFNetwork PAC::rlsPerform(void*)
CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
Regression?
Yes, compared with .NET 10.
The same app works on the same devices with .NET 10 (Mono, AOT) and with .NET 11 on Android (CoreCLR, JIT).
The declaration bug itself is old. What changed in .NET 11 is that this code now runs on the CoreCLR interpreter, which doesn't zero the upper half of 32-bit arguments. The ABI doesn't require it to.
Known Workarounds
Keep MacProxy out of the request path before any SocketsHttpHandler-based client is created:
// No proxy for SocketsHttpHandler clients.
HttpClient.DefaultProxy = new WebProxy();
// Move IHttpClientFactory clients to HttpClientHandler (NSUrlSessionHandler), which resolves proxies natively.
services.ConfigureHttpClientDefaults(http =>
http.ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler()));
With the first line, SocketsHttpHandler clients and ClientWebSocket ignore the device's proxy and connect directly.
Configuration
- .NET: SDK 11.0.100-rc.1.26425.128 (runtime 11.0.0-rc.1.26425.128).
- Workload set 11.0.100-rc.1.26458.5 (Microsoft.iOS.Sdk.net11.0_26.5 26.5.12193-net11-rc.1).
- MAUI 11.0.0-rc.1.26451.6.
- CoreCLR (the default for net11.0-ios), with the interpreter and composite R2R.
- Built with dotnet publish -f net11.0-ios -p:RuntimeIdentifier=ios-arm64 using Xcode 26.6.
- OS: iOS 18.6 (22G86) on iPhone 16 (iPhone17,3). Also reproduced on the iOS 26.3 simulator with the iossimulator-arm64 11.0.0-rc.1.26425.128 runtime pack.
- Architecture: ARM64.
- Specific to this configuration? Yes. It only happens where System.Net.Http runs on the CoreCLR interpreter. It doesn't reproduce with the JIT (macOS, Android) or Mono AOT (.NET 10).
- Blazor: the app is a MAUI Blazor Hybrid app (BlazorWebView), but Blazor isn't involved. The crash is in SocketsHttpHandler's proxy lookup.
Other information
No response
- Lenguaje dominante
- C#
- Estrellas
- 18.3k
- Forks
- 5.6k
- Merge medio
- 2 d 18 h
- PR fusionados (30 d)
- 617
Preparar el entorno
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de dotnet/runtime
-
area-System.Linq untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
dotnet/runtime#134736 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
area-System.Numerics.Tensors untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
dotnet/runtime#134691 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
area-System.Threading blocking-clean-ci Known Build Error untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
dotnet/runtime#134679 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
-
ARM64: conditional compare rejects negative immediates the emitter can already encode as `ccmn`Abiertoarea-CodeGen-coreclr performance
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
dotnet/runtime#134663 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
area-System.Security untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
dotnet/runtime#134659 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de dotnet/runtime
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
microsoft/fluentui-blazor#5364 ·
Los mantenedores suelen responder en 1 día
-
.NET triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
microsoft/agent-framework#8811 ·
Los mantenedores suelen responder en 1 día
-
.NET Docs
Dificultad 1/5 Menos de una hora Aptitud para principiantes 82/100
getsentry/sentry-dotnet#5637 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
QuantConnect/Lean#9842 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
NethermindEth/nethermind#14012 ·
Los mantenedores suelen responder en 1 día