Crash (double free) in MapboxCommon location dispatch on com.mapbox.threadpool: "pointer being freed was not allocated"

Abierto
#2,459 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
ios, swift

Línea de trabajo

Start by examining the location update dispatch and region monitor paths in MapboxCommon; the report names CustomDeviceLocationProvider::dispatchLocationUpdate and RegionsMonitorService::createRegionsMonitor, but does not identify source files or a reproducible case. First look for existing location provider and region monitor tests, then investigate the reported race around location updates. Done means reproducing or isolating the invalid free and adding coverage for the corrected behavior.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

auto-triaged bug :beetle: p2

[redacted with Claude, rare race, happened only once]

Environment

  • Xcode version: 27.2 (27B52)
  • iOS version: 27.2.1
  • Devices affected: one, once, iPhone SE (2nd generation)
  • Maps SDK Version: mapbox-maps-ios 11.30.1, mapbox-core-maps-ios 11.30.1, mapbox-common-ios 24.30.1 (Swift Package Manager, deployment target iOS 16.0)

Observed behavior and steps to reproduce

Our production app crashes with SIGABRT ("pointer being freed was not allocated") on a com.mapbox.threadpool thread while MapboxCommon dispatches a location update. No app frame is on the crashed thread. Crashlytics reported it as a fatal crash.

Setup:

  • the map uses the SwiftUI API, Map(viewport:) { Puck2D(bearing: .course) }, with the default LocationDataModel (AppleLocationProvider);
  • we do not use the Navigation SDK, geofencing, or LocationDataModel.createCore();
  • telemetry is left at its default (enabled);
  • location permission is When In Use only, with no UIBackgroundModes.

Steps to reproduce: unknown. We have not been able to reproduce it locally and only have the Crashlytics report. It looks like a rare race.

Crashed thread:

Crashed: com.mapbox.threadpool
0  libsystem_kernel.dylib         0xb1fc __pthread_kill + 8
1  libsystem_pthread.dylib        0x7440 pthread_kill + 268
2  libsystem_c.dylib              0x7996c abort + 148
3  libsystem_malloc.dylib         0x24754 malloc_report + 566
4  libsystem_malloc.dylib         0x24794 malloc_report + 64
5  libsystem_malloc.dylib         0x23f04 ___BUG_IN_CLIENT_OF_LIBMALLOC_POINTER_BEING_FREED_WAS_NOT_ALLOCATED + 64
6  MapboxCommon                   0x2b822c mapbox::bindgen::mapbox::common::location::RegionsMonitorService::createRegionsMonitor(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, bool, bool) + 29772
7  MapboxCommon                   0x2bcf80 mapbox::common::location::CustomDeviceLocationProvider::dispatchLocationUpdate(std::__1::vector<mapbox::common::location::Location, std::__1::allocator<mapbox::common::location::Location>>&&) + 3980
8  MapboxCommon                   0x183b10 mapbox::bindgen::mapbox::common::ConfigurationServiceObserver::didEncounterError(mapbox::common::ConfigurationServiceError const&) + 56592
9  MapboxCommon                   0x1835e8 mapbox::bindgen::mapbox::common::ConfigurationServiceObserver::didEncounterError(mapbox::common::ConfigurationServiceError const&) + 55272
10 MapboxCommon                   0x1839b8 mapbox::bindgen::mapbox::common::ConfigurationServiceObserver::didEncounterError(mapbox::common::ConfigurationServiceError const&) + 56248
11 MapboxCommon                   0x22172c mapbox::common::ValueConverter::toJson(mapbox::feature::value const&, unsigned int) + 8896
12 MapboxCommon                   0x1b9eac mapbox::common::platform::processTask(std::__1::function<void ()> const&) + 5564
13 libdispatch.dylib              0x1ccc _dispatch_call_block_and_release + 32
14 libdispatch.dylib              0x1bfb4 _dispatch_client_callout + 16
15 libdispatch.dylib              0x6700 _dispatch_continuation_pop + 316
16 libdispatch.dylib              0x5dbc _dispatch_async_redirect_invoke + 408
17 libdispatch.dylib              0x149f8 _dispatch_root_queue_drain + 640
18 libdispatch.dylib              0x150e4 _dispatch_worker_thread2 + 196
19 libsystem_pthread.dylib        0x11fc _pthread_wqthread + 232
20 libsystem_pthread.dylib        0x910 start_wqthread + 8

At the same moment:

  • the main thread is inside CoreLocation delivering locations (_LocationEssentials copyLocationsFromLocationMessagePayload);
  • a com.mapbox.common.location.sharedRunloop thread is running, so MapboxCommon's own location service is active;
  • a second com.mapbox.threadpool thread is blocked in _dispatch_sync_f_slow inside MapboxCommon.
Full stack trace (all threads)
com.apple.main-thread
0  _LocationEssentials            0x38dc copyLocationsFromLocationMessagePayload + 2530
1  CoreLocation                   0x71bc CLClientCreateWithBundleIdentifierAndPathWithWebsiteOnSilo + 17336
2  LocationSupport                0x154c CLProfilingIdentifySiloInvocation + 396
3  CoreFoundation                 0x818ac __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 28
4  CoreFoundation                 0x3ad30 __CFRunLoopDoBlocks + 356
5  CoreFoundation                 0x3a6c8 __CFRunLoopRun + 1268
6  CoreFoundation                 0x3b7e4 _CFRunLoopRunSpecificWithOptions + 344
7  GraphicsServices               0xf24 GSEventRunModal + 120
8  UIKitCore                      0xbaaa4 UIApplicationMain + 336
9  SwiftUI                        0x47ae4 closure #1 in KitRendererCommon(_:) + 168
10 SwiftUI                        0x4127c runApp<A>(_:) + 136
11 SwiftUI                        0x4113c static App.main() + 172
12 Locamino                       0x124b88 main + 4301785992 (ActionPackedIOSApp.swift:4301785992)
13 ???                            0x185eb0524 (Manquant)

Thread
0  libsystem_pthread.dylib        0x908 start_wqthread + 6542473478

com.mapbox.threadpool
0  libsystem_kernel.dylib         0x7134 __ulock_wait + 8
1  libdispatch.dylib              0x3ce4 _dlock_wait + 56
2  libdispatch.dylib              0x3b08 _dispatch_thread_event_wait_slow + 56
3  libdispatch.dylib              0x124c0 __DISPATCH_WAIT_FOR_QUEUE__ + 500
4  libdispatch.dylib              0x11fcc _dispatch_sync_f_slow + 144
5  MapboxCommon                   0x1b9928 mapbox::common::platform::processTask(std::__1::function<void ()> const&) + 4152
6  MapboxCommon                   0x1b947c mapbox::common::platform::processTask(std::__1::function<void ()> const&) + 2956
7  MapboxCommon                   0x1b9564 mapbox::common::platform::processTask(std::__1::function<void ()> const&) + 3188
8  MapboxCommon                   0x1e5a4c mapbox::common::settings::internal::getTelemetryEventsBaseUrlOverrideSettingName() + 1612
9  MapboxCommon                   0x1ba1b0 mapbox::common::platform::processTask(std::__1::function<void ()> const&) + 6336
10 MapboxCommon                   0x1b9ecc mapbox::common::platform::processTask(std::__1::function<void ()> const&) + 5596
11 libdispatch.dylib              0x1ccc _dispatch_call_block_and_release + 32
12 libdispatch.dylib              0x1bfb4 _dispatch_client_callout + 16
13 libdispatch.dylib              0x6700 _dispatch_continuation_pop + 316
14 libdispatch.dylib              0x5dbc _dispatch_async_redirect_invoke + 408
15 libdispatch.dylib              0x149f8 _dispatch_root_queue_drain + 640
16 libdispatch.dylib              0x150e4 _dispatch_worker_thread2 + 196
17 libsystem_pthread.dylib        0x11fc _pthread_wqthread + 232
18 libsystem_pthread.dylib        0x910 start_wqthread + 8

com.google.firebase.crashlytics.MachExceptionServer
0  libsystem_kernel.dylib         0xcd4 mach_msg2_trap + 8
1  libsystem_kernel.dylib         0x4308 mach_msg2_internal + 76
2  libsystem_kernel.dylib         0x4228 mach_msg_overwrite + 424
3  libsystem_kernel.dylib         0x4074 mach_msg + 24
4  Locamino                       0x9e5c68 FIRCLSMachExceptionServer + 198 (FIRCLSMachException.c:198)
5  libsystem_pthread.dylib        0x401c _pthread_start + 136
6  libsystem_pthread.dylib        0x91c thread_start + 8

com.mapbox.common.MB Coalescer
0  libsystem_kernel.dylib         0x65f8 __psynch_cvwait + 8
1  libsystem_pthread.dylib        0x1da0 _pthread_cond_wait + 980
2  libc++.1.dylib                 0xaae8 std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) + 32
3  MapboxCommon                   0x215558 mapbox::common::SystemInformationProvider::getSystemInformation() + 28392
4  libsystem_pthread.dylib        0x401c _pthread_start + 136
5  libsystem_pthread.dylib        0x91c thread_start + 8

com.mapbox.common.MB HTTPRequests
0  libsystem_kernel.dylib         0x65f8 __psynch_cvwait + 8
1  libsystem_pthread.dylib        0x1da0 _pthread_cond_wait + 980
2  libc++.1.dylib                 0xaae8 std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) + 32
3  MapboxCommon                   0x215558 mapbox::common::SystemInformationProvider::getSystemInformation() + 28392
4  libsystem_pthread.dylib        0x401c _pthread_start + 136
5  libsystem_pthread.dylib        0x91c thread_start + 8

com.mapbox.common.MB-CPUMonitor
0  libsystem_kernel.dylib         0x65f8 __psynch_cvwait + 8
1  libsystem_pthread.dylib        0x1da0 _pthread_cond_wait + 980
2  libc++.1.dylib                 0xaae8 std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) + 32
3  MapboxCommon                   0x1c9b90 mapbox::common::decompressZstd(char const*, unsigned long, unsigned long) + 2988
4  MapboxCommon                   0x1c9610 mapbox::common::decompressZstd(char const*, unsigned long, unsigned long) + 1580
5  libsystem_pthread.dylib        0x401c _pthread_start + 136
6  libsystem_pthread.dylib        0x91c thread_start + 8

com.mapbox.common.location.sharedRunloop
0  libsystem_kernel.dylib         0xcd4 mach_msg2_trap + 8
1  libsystem_kernel.dylib         0x4308 mach_msg2_internal + 76
2  libsystem_kernel.dylib         0x4228 mach_msg_overwrite + 424
3  libsystem_kernel.dylib         0x4074 mach_msg + 24
4  CoreFoundation                 0x3b45c __CFRunLoopServiceMachPort + 136
5  CoreFoundation                 0x3a428 __CFRunLoopRun + 596
6  CoreFoundation                 0x3b7e4 _CFRunLoopRunSpecificWithOptions + 344
7  CoreFoundation                 0xdd3ac CFRunLoopRun + 64
8  MapboxCommon                   0x2bb4a0 mapbox::bindgen::mapbox::common::location::RegionsMonitorService::createRegionsMonitor(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, bool, bool) + 42688
9  Foundation                     0x205d78 __NSThread__start__ + 732
10 libsystem_pthread.dylib        0x401c _pthread_start + 136
11 libsystem_pthread.dylib        0x91c thread_start + 8

com.apple.NSURLConnectionLoader
0  libsystem_kernel.dylib         0xcd4 mach_msg2_trap + 8
1  libsystem_kernel.dylib         0x4308 mach_msg2_internal + 76
2  libsystem_kernel.dylib         0x4228 mach_msg_overwrite + 424
3  libsystem_kernel.dylib         0x4074 mach_msg + 24
4  CoreFoundation                 0x3b45c __CFRunLoopServiceMachPort + 136
5  CoreFoundation                 0x3a428 __CFRunLoopRun + 596
6  CoreFoundation                 0x3b7e4 _CFRunLoopRunSpecificWithOptions + 344
7  CFNetwork                      0xe1394 +[__CFN_CoreSchedulingSetRunnable _run:] + 392
8  Foundation                     0x205d78 __NSThread__start__ + 732
9  libsystem_pthread.dylib        0x401c _pthread_start + 136
10 libsystem_pthread.dylib        0x91c thread_start + 8

Thread
0  libsystem_pthread.dylib        0x908 start_wqthread + 6542473478

Thread
0  libsystem_pthread.dylib        0x908 start_wqthread + 6542473478

com.mapbox.common.MB TileStore RW
0  libsystem_kernel.dylib         0x65f8 __psynch_cvwait + 8
1  libsystem_pthread.dylib        0x1da0 _pthread_cond_wait + 980
2  libc++.1.dylib                 0xab80 std::__1::condition_variable::__do_timed_wait(std::__1::unique_lock<std::__1::mutex>&, std::__1::chrono::time_point<std::__1::chrono::system_clock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l>>>) + 104
3  MapboxCommon                   0x215600 mapbox::common::SystemInformationProvider::getSystemInformation() + 28560
4  libsystem_pthread.dylib        0x401c _pthread_start + 136
5  libsystem_pthread.dylib        0x91c thread_start + 8

com.mapbox.common.MB TileStore RO
0  libsystem_kernel.dylib         0x65f8 __psynch_cvwait + 8
1  libsystem_pthread.dylib        0x1da0 _pthread_cond_wait + 980
2  libc++.1.dylib                 0xaae8 std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) + 32
3  MapboxCommon                   0x215558 mapbox::common::SystemInformationProvider::getSystemInformation() + 28392
4  libsystem_pthread.dylib        0x401c _pthread_start + 136
5  libsystem_pthread.dylib        0x91c thread_start + 8

com.mapbox.common.AssetFS
0  libsystem_kernel.dylib         0x65f8 __psynch_cvwait + 8
1  libsystem_pthread.dylib        0x1da0 _pthread_cond_wait + 980
2  libc++.1.dylib                 0xaae8 std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) + 32
3  MapboxCommon                   0x215558 mapbox::common::SystemInformationProvider::getSystemInformation() + 28392
4  libsystem_pthread.dylib        0x401c _pthread_start + 136
5  libsystem_pthread.dylib        0x91c thread_start + 8

com.mapbox.common.TileStoreFS
0  libsystem_kernel.dylib         0x65f8 __psynch_cvwait + 8
1  libsystem_pthread.dylib        0x1da0 _pthread_cond_wait + 980
2  libc++.1.dylib                 0xaae8 std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) + 32
3  MapboxCommon                   0x215558 mapbox::common::SystemInformationProvider::getSystemInformation() + 28392
4  libsystem_pthread.dylib        0x401c _pthread_start + 136
5  libsystem_pthread.dylib        0x91c thread_start + 8

com.mapbox.common.LocalFS
0  libsystem_kernel.dylib         0x65f8 __psynch_cvwait + 8
1  libsystem_pthread.dylib        0x1da0 _pthread_cond_wait + 980
2  libc++.1.dylib                 0xaae8 std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) + 32
3  MapboxCommon                   0x215558 mapbox::common::SystemInformationProvider::getSystemInformation() + 28392
4  libsystem_pthread.dylib        0x401c _pthread_start + 136
5  libsystem_pthread.dylib        0x91c thread_start + 8

com.mapbox.common.OnlineFS
0  libsystem_kernel.dylib         0x65f8 __psynch_cvwait + 8
1  libsystem_pthread.dylib        0x1da0 _pthread_cond_wait + 980
2  libc++.1.dylib                 0xab80 std::__1::condition_variable::__do_timed_wait(std::__1::unique_lock<std::__1::mutex>&, std::__1::chrono::time_point<std::__1::chrono::system_clock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l>>>) + 104
3  MapboxCommon                   0x215600 mapbox::common::SystemInformationProvider::getSystemInformation() + 28560
4  libsystem_pthread.dylib        0x401c _pthread_start + 136
5  libsystem_pthread.dylib        0x91c thread_start + 8

com.mapbox.common.ResourceLoader
0  libsystem_kernel.dylib         0x65f8 __psynch_cvwait + 8
1  libsystem_pthread.dylib        0x1da0 _pthread_cond_wait + 980
2  libc++.1.dylib                 0xaae8 std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) + 32
3  MapboxCommon                   0x215558 mapbox::common::SystemInformationProvider::getSystemInformation() + 28392
4  libsystem_pthread.dylib        0x401c _pthread_start + 136
5  libsystem_pthread.dylib        0x91c thread_start + 8

com.mapbox.common.MtlGpuUploader
0  libsystem_kernel.dylib         0x65f8 __psynch_cvwait + 8
1  libsystem_pthread.dylib        0x1da0 _pthread_cond_wait + 980
2  libc++.1.dylib                 0xaae8 std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&) + 32
3  MapboxCommon                   0x215558 mapbox::common::SystemInformationProvider::getSystemInformation() + 28392
4  libsystem_pthread.dylib        0x401c _pthread_start + 136
5  libsystem_pthread.dylib        0x91c thread_start + 8

Crashed: com.mapbox.threadpool
0  libsystem_kernel.dylib         0xb1fc __pthread_kill + 8
1  libsystem_pthread.dylib        0x7440 pthread_kill + 268
2  libsystem_c.dylib              0x7996c abort + 148
3  libsystem_malloc.dylib         0x24754 malloc_report + 566
4  libsystem_malloc.dylib         0x24794 malloc_report + 64
5  libsystem_malloc.dylib         0x23f04 ___BUG_IN_CLIENT_OF_LIBMALLOC_POINTER_BEING_FREED_WAS_NOT_ALLOCATED + 64
6  MapboxCommon                   0x2b822c mapbox::bindgen::mapbox::common::location::RegionsMonitorService::createRegionsMonitor(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, bool, bool) + 29772
7  MapboxCommon                   0x2bcf80 mapbox::common::location::CustomDeviceLocationProvider::dispatchLocationUpdate(std::__1::vector<mapbox::common::location::Location, std::__1::allocator<mapbox::common::location::Location>>&&) + 3980
8  MapboxCommon                   0x183b10 mapbox::bindgen::mapbox::common::ConfigurationServiceObserver::didEncounterError(mapbox::common::ConfigurationServiceError const&) + 56592
9  MapboxCommon                   0x1835e8 mapbox::bindgen::mapbox::common::ConfigurationServiceObserver::didEncounterError(mapbox::common::ConfigurationServiceError const&) + 55272
10 MapboxCommon                   0x1839b8 mapbox::bindgen::mapbox::common::ConfigurationServiceObserver::didEncounterError(mapbox::common::ConfigurationServiceError const&) + 56248
11 MapboxCommon                   0x22172c mapbox::common::ValueConverter::toJson(mapbox::feature::value const&, unsigned int) + 8896
12 MapboxCommon                   0x1b9eac mapbox::common::platform::processTask(std::__1::function<void ()> const&) + 5564
13 libdispatch.dylib              0x1ccc _dispatch_call_block_and_release + 32
14 libdispatch.dylib              0x1bfb4 _dispatch_client_callout + 16
15 libdispatch.dylib              0x6700 _dispatch_continuation_pop + 316
16 libdispatch.dylib              0x5dbc _dispatch_async_redirect_invoke + 408
17 libdispatch.dylib              0x149f8 _dispatch_root_queue_drain + 640
18 libdispatch.dylib              0x150e4 _dispatch_worker_thread2 + 196
19 libsystem_pthread.dylib        0x11fc _pthread_wqthread + 232
20 libsystem_pthread.dylib        0x910 start_wqthread + 8

Thread
0  libsystem_pthread.dylib        0x908 start_wqthread + 6542473478

Expected behavior

Location updates are dispatched without crashing.

Notes / preliminary analysis

The symbol names in the trace are the nearest exported symbols, since internal symbols are stripped. The offsets (+29772, +56592) are too large to be real. Running atos on the MapboxCommon.framework (ios-arm64) binary from the 24.30.1 SPM artifact gives the real offsets inside unnamed functions:

Frame Address Real offset
6 0x2b822c function at 0x2b7be0 + 1612
7 0x2bcf80 function at 0x2bcf24 + 92

Frame 7 (function at 0x2bcf24) locks a weak_ptr (__shared_weak_count::lock), loads the observer at this+0x18, and calls it through vtable+0x28 with the moved std::vector<Location>:

2bcf40  ldr  x0, [x0, #0x20]
2bcf4c  bl   __shared_weak_count::lock
2bcf5c  ldr  x21, [x21, #0x18]
2bcf68  ldr  x8, [x21]
2bcf6c  ldr  x9, [x8, #0x28]
2bcf7c  blr  x9                ; -> frame 6

Frame 6 (function at 0x2b7be0) appends to a vector member at this+0x48 (begin / end / capacity at +0x48 / +0x50 / +0x58) with 128-byte elements, which matches sizeof(Location). When the vector reallocates, it copies the old elements into the new buffer and deletes the old one. That operator delete aborts:

2b81f4  ldp  x23, x9, [x19, #0x48]   ; old begin, end
2b8214  bl   _memcpy                 ; move elements to the new buffer
2b8218  stp  x21, x28, [x19, #0x48]
2b821c  str  x20, [x19, #0x58]
2b8228  bl   operator delete(void*)  ; old buffer -> "pointer being freed was not allocated"

We found no mutex or lock call in that function. The old buffer was already freed, which points to two threads growing the same vector at the same time: a data race causing a double free.

The same function's lazy-init branch calls getOrCreateDefaultProvider and setRegionsMonitorProvider:. Strings in the binary also tie the device location provider to telemetry (TelemetryServiceWorker::startLocationEventDelegate, TelemetryLocationProviderImpl::getDeviceLocationProvider, ios_background_region_radius). Since our app never uses MapboxCommon location directly, we believe this is the location collection of the telemetry service.

Additional links and references

  • The full stack trace is included above, in the collapsed section.
  • We searched existing mapbox-maps-ios and mapbox-common-ios issues and found no report with this signature.
Lenguaje dominante
Swift
Estrellas
601
Forks
198
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de mapbox/mapbox-maps-ios

Todos los issues de mapbox/mapbox-maps-ios

Issues similares

Más issues de Swift

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.