Heap corruption / double free in MapboxCoreMaps when a CarPlay MapView renders while its scene is in the background (11.31.1)
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 30/100
Línea de trabajo
Start with the MapView display state and lifecycle paths described in the report, especially sceneWillDeactivate, sceneDidEnterBackground, reduceMemoryUse(), MetalView.draw, and MapView.updateFromDisplayLink; inspect related issues #2052 and #2195. Reproduce with CarPlay Simulator and Guard Malloc, keeping the hidden map rendering while the scene is in the background. Done means background rendering or skipped frames no longer corrupt memory across the reported cycles.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Environment
- Xcode version: 27.0 (27A266a)
- iOS version: 26.6.2 (reproduced), also seen in the field on 26.6.x, 26.7.1, 27.0
- Devices affected: iPhone 15 (iPhone16,1) on our test rig; in the field iPhone 15–17 Pro
- Maps SDK Version: MapboxMaps 11.31.1, MapboxCoreMaps 11.31.1, MapboxCommon 24.31.1 (via mapbox_maps_flutter 2.31.1). Same crashes on 11.20.2 / 24.20.2.
Observed behavior and steps to reproduce
Our app has two MapViews in one process: the phone map (Flutter plugin) and a native MapView inside the CarPlay CPWindow. If the CarPlay MapView keeps rendering while its CPTemplateApplicationScene is in .background (car screen showing CarPlay home, Music or another app), the app crashes with heap corruption inside MapboxCoreMaps as soon as the app comes back from the background, or when the car scene connects. None of our code is on the crashing stack.
Steps (iPhone over USB + CarPlay Simulator):
- Create the CarPlay MapView with
mapView.displayState = [.foregroundActive, .foregroundInactive, .background]. - Connect CarPlay, open the app on the car screen, then switch the car screen to the CarPlay home screen. The scene goes to
.backgroundand MapView pauses (connectedScene cleared insceneWillDeactivate). - Make the hidden map keep drawing: post
UIScene.didActivateNotificationwith the car scene as the object. We did this from a render watchdog after 4 s without frames. On 11.20.2 this step isn't needed: the display link keeps running in the background once.backgroundis allowed. - On the phone, open Settings for ~4 s, then bring the app back. Repeat.
- Run with Guard Malloc to catch it right away:
xcrun devicectl device process launch -e '{"MallocProbGuard":"1"}' <bundle id>.
Variant: with the app in the background, disconnect and reconnect the car while it shows the home screen. The car scene connects in .background; if the map is nudged into drawing (same notification on the first layout pass), the app crashes within about a second.
Results:
- Hidden map drawing: 5 of 5 runs crashed within 1–3 cycles.
- Hidden map left paused: 0 crashes in 75 cycles.
- Car map visible (scene active) with the phone going to the background and back: 0 in 30.
- No car connected: 0 in 30.
- Without Guard Malloc: no crash in 30 cycles in any variant (the corruption is silent there).
Typical messages:
BUG IN CLIENT OF LIBMALLOC: free to empty or invalid chunk detected (likely double-free)oncom.mapbox.threadpoolBUG IN CLIENT OF LIBMALLOC: memory corruption of free block(operator new on a threadpool thread, once on the main thread insideStyleManager::addStyleImage)- In the field also
Pure virtual function called!inmapbox::common::RunLoop::~RunLoopon the main thread
Faulting frames (MapboxCoreMaps 11.31.1 UUID A6900208-95DF-33BA-9A4B-AF77F668EE78, MapboxCommon 24.31.1 UUID 6A8EDD2C-FA7B-33FF-836E-13F17C762895):
1) _xzm_free_abort < _xzm_free < MapboxCoreMaps +0x588a08 +0x593b54 +0x48bb18 +0xa19c94 +0xa28020 +0xa09cc4 < MapboxCommon +0x1bd218 +0x220d04 +0x1ba624
2) _xzm_free_abort < _xzm_free < MapboxCoreMaps +0x9f6fdc +0xa1b958 +0xa1c0f0 < MapboxCommon +0x220d04 +0x1ba624
(main thread at the same time: MapboxCoreMaps +0x6eaf70 +0x7b829c +0x79d580 +0x7430ec < MetalView.draw < MapView.updateFromDisplayLink)
3) _xzm_xzone_malloc_freelist_outlined < operator new < MapboxCoreMaps +0xa4f4d8 +0xa4c7e0 +0xa2268c +0xa18a40 +0xa28020 +0xa09cc4 < MapboxCommon +0x220d04
4) main thread: _xzm_xzone_malloc_freelist_outlined < operator new < MapboxCoreMaps StyleManager::addStyleImage (+0x1590a0) +0xef43c < StyleManager.addImage
5) _xzm_free_abort < _xzm_free < MapboxCommon +0x1bd250 +0x220d04 +0x1ba624
The five full Apple crash reports are attached.
Expected behavior
DisplayState.background is a documented option ("allows the map to continue updating while the app is backgrounded"). With it set, the map should either render safely or skip frames when the GPU isn't available. It should never corrupt the heap. A synthetic or real scene activation shouldn't be able to put the renderer into a state that leads to a double free.
Notes / preliminary analysis
- In production this showed up as about 170 native crashes since we shipped CarPlay, almost all in CarPlay sessions. A build with CarPlay turned off had none. Without Guard Malloc the double free is usually silent and the app dies later somewhere unrelated (a TLS handshake, our own Swift code, Network.framework), so the crashes were spread over many unrelated-looking signatures.
- In 2 of the 5 reports the main thread was inside MapboxCoreMaps rendering (
MetalView.draw←updateFromDisplayLink) at the moment a threadpool task hit the double free. - Two guesses, not verified:
sceneDidEnterBackgroundalways callsreduceMemoryUse()(mapboxMap.reduceMemoryUse()+metalView?.releaseDrawables()), even when.backgroundis allowed and the display link keeps running.- Rendering in the background means Metal command buffers get rejected (we've seen
IOGPUCommandBufferCallbackErrorBackgroundExecutionNotPermitted). v10.20.0 fixed "commit an already committed command buffer" after a failed buffer; maybe a similar path exists in v11.
- Workaround on our side: we removed
.backgroundfrom the CarPlay MapView'sdisplayStateand stopped posting the activation while the car scene is hidden. That made it go away on the rig. - Could you symbolicate the offsets above, and confirm whether
.backgroundis meant to be safe for a CarPlay MapView? Happy to put together a small sample project or try a debug build if that helps.
Additional links and references
- Possibly related: #2052 (MapboxCoreMaps crashes with "Pure virtual function called" and heap corruption), #2195 (crash in MetalView.draw, xzone malloc trap).
- No fix for this in the 11.32.x or 11.33.0-rc.1 release notes as far as we can see.
- Lenguaje dominante
- Swift
- Estrellas
- 601
- Forks
- 198
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
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 mapbox/mapbox-maps-ios
-
auto-triaged bug :beetle: p3 SwiftUI
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
mapbox/mapbox-maps-ios#2452 · 6 reacciones ·
-
Map elements regression 11.33.xAbiertoauto-triaged bug :beetle: p2
Dificultad 4/5 3-5 días Aptitud para principiantes 42/100
mapbox/mapbox-maps-ios#2451 ·
-
auto-triaged bug :beetle: needs info p3 performance :zap:
Dificultad 5/5 Más de una semana Aptitud para principiantes 22/100
mapbox/mapbox-maps-ios#2450 · 1 comentario ·
-
auto-triaged bug :beetle: p1
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
mapbox/mapbox-maps-ios#2449 · 4 comentarios ·
-
auto-triaged bug :beetle: p2
Dificultad 3/5 1-2 días Aptitud para principiantes 55/100
mapbox/mapbox-maps-ios#2448 ·
Todos los issues de mapbox/mapbox-maps-ios
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 5 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Provenance-Emu/SkinKit#42 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
lwouis/alt-tab-macos#6154 ·
-
bug mac アプリ: コード アプリ: チャット 優先: 中 要トリアージ
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
yksr-melt/Meltype#1346 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100