Skip to content

fix: Potential MPURLRequestBuilder crash#578

Merged
jamesnrokt merged 4 commits intomainfrom
fix/MPURLRequestBuilder-build-crash-v2
Feb 13, 2026
Merged

fix: Potential MPURLRequestBuilder crash#578
jamesnrokt merged 4 commits intomainfrom
fix/MPURLRequestBuilder-build-crash-v2

Conversation

@jamesnrokt
Copy link
Copy Markdown
Collaborator

Background

Crash observed in -[MPURLRequestBuilder build] on com.mparticle.messageQueue, could potentially be related to unsafe concurrent access to apiKey/secret on MPStateMachine.

Crashed: com.mparticle.messageQueue
0  libsystem_malloc.dylib         0x30a0 _xzm_xzone_malloc_freelist_outlined + 864
1  CoreFoundation                 0x8084 __CFStringAppendFormatCore + 6952
2  CoreFoundation                 0x122e4 _CFStringCreateWithFormatAndArgumentsReturningMetadata + 184
3  CoreFoundation                 0x12398 _CFStringCreateWithFormatAndArgumentsAux2 + 44
4  Foundation                     0x9b2bb0 +[NSString stringWithFormat:] + 68
5  mParticle_Apple_SDK            0x6340 -[MPURLRequestBuilder build] + 3800
6  mParticle_Apple_SDK            0x45130 -[MPConnector responseFromGetRequestToURL:] + 120
7  mParticle_Apple_SDK            0x575d8 -[MPNetworkCommunication_PRIVATE requestConfig:withCompletionHandler:] + 952
8  mParticle_Apple_SDK            0x6d34c -[MPBackendController_PRIVATE requestConfig:] + 128
9  mParticle_Apple_SDK            0x7450c -[MPBackendController_PRIVATE checkForKitsAndUploadWithCompletionHandler:] + 96
10 mParticle_Apple_SDK            0x743a0 -[MPBackendController_PRIVATE waitForKitsAndUploadWithCompletionHandler:] + 96
11 mParticle_Apple_SDK            0x77a80 __59-[MPBackendController_PRIVATE beginBackgroundTimeCheckLoop]_block_invoke.194 + 72
12 libdispatch.dylib              0x1adc _dispatch_call_block_and_release + 32
13 libdispatch.dylib              0x1b7fc _dispatch_client_callout + 16
14 libdispatch.dylib              0xa468 _dispatch_lane_serial_drain + 740
15 libdispatch.dylib              0xaf44 _dispatch_lane_invoke + 388
16 libdispatch.dylib              0x153ec _dispatch_root_queue_drain_deferred_wlh + 292
17 libdispatch.dylib              0x14ce4 _dispatch_workloop_worker_thread + 692
18 libsystem_pthread.dylib        0x13b8 _pthread_wqthread + 292
19 libsystem_pthread.dylib        0x8c0 start_wqthread + 8

What Has Changed

  • MPStateMachine.h: apiKey and secret changed from nonatomic to atomic; removed __attribute__((const)) which could interfere with atomicity guarantees.
  • MPURLRequestBuilder.m: Capture apiKey and secret into local variables once at the top of build; bail early if either is nil.
  • MPURL.h: Made url and defaultURL properties readonly.
  • Added a thread-safety stress test for concurrent apiKey/secret access.

Checklist

  • I have performed a self-review of my own code.
  • I have made corresponding changes to the documentation.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have tested this locally.

Additional Notes

  • N/A

Reference Issue (For employees only. Ignore if you are an outside contributor)

@jamesnrokt jamesnrokt requested a review from a team as a code owner February 12, 2026 21:51
@jamesnrokt jamesnrokt changed the title Fix/mpurl request builder build crash v2 fix: MPURLRequestBuilder crash Feb 12, 2026
@jamesnrokt jamesnrokt changed the title fix: MPURLRequestBuilder crash fix: Potential MPURLRequestBuilder crash Feb 12, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 12, 2026

📦 SDK Size Impact Report

Measures how much the SDK adds to an app's size (with-SDK minus without-SDK).

Metric Target Branch This PR Change
App Bundle Impact 1.82 MB 1.82 MB +N/A
Executable Impact 896 bytes 896 bytes +N/A
XCFramework Size 9.48 MB 9.48 MB +N/A

➡️ SDK size impact change is minimal.

Raw measurements

Target branch (main):

{"baseline_app_size_kb":84,"baseline_executable_size_bytes":75464,"with_sdk_app_size_kb":1944,"with_sdk_executable_size_bytes":76360,"sdk_impact_kb":1860,"sdk_executable_impact_bytes":896,"xcframework_size_kb":9704}

This PR:

{"baseline_app_size_kb":84,"baseline_executable_size_bytes":75464,"with_sdk_app_size_kb":1944,"with_sdk_executable_size_bytes":76360,"sdk_impact_kb":1860,"sdk_executable_impact_bytes":896,"xcframework_size_kb":9704}

thomson-t
thomson-t previously approved these changes Feb 13, 2026
denischilik
denischilik previously approved these changes Feb 13, 2026
@denischilik denischilik self-requested a review February 13, 2026 14:01
There's logic allowing network requests without the header x-mp-signature
@jamesnrokt jamesnrokt dismissed stale reviews from denischilik and thomson-t via bf95b86 February 13, 2026 15:25
@jamesnrokt jamesnrokt merged commit 70c0076 into main Feb 13, 2026
15 checks passed
@jamesnrokt jamesnrokt deleted the fix/MPURLRequestBuilder-build-crash-v2 branch February 13, 2026 19:15
BrandonStalnaker pushed a commit that referenced this pull request Feb 17, 2026
* fix: Potential crash in MPURLRequestBuilder

* Add validation for API key and secret

* Allow nil secrets and key

There's logic allowing network requests without the header x-mp-signature

(cherry picked from commit 70c0076)
BrandonStalnaker added a commit that referenced this pull request Feb 17, 2026
* fix: Use Defensive Copy for ActiveKitsRegistry (#571)

(cherry picked from commit e5d5e27)

* fix: Mitigate Thread-safety of DateFormatter (#574)

(cherry picked from commit 7b36691)

* fix: MPURLRequestBuilder build crash (#575)

* fix: MPURLRequestBuilder build crash

* Change signature to nullable

(cherry picked from commit 604afee)

* fix: app crash from [MPUpload description] (#572)

* fix: app crash from [MPUpload description]

Stacktrace
```
0  libsystem_malloc.dylib         0x30a0 _xzm_xzone_malloc_freelist_outlined + 864
1  Foundation                     0x4804 -[NSString quotedStringRepresentation] + 132
2  Foundation                     0x4724 -[NSString _stringRepresentation] + 360
3  CoreFoundation                 0x14a580 -[NSDictionary descriptionWithLocale:indent:] + 1128
4  CoreFoundation                 0x14a5ac -[NSDictionary descriptionWithLocale:indent:] + 1172
5  Foundation                     0x36b4 _NSDescriptionWithLocaleFunc + 56
6  CoreFoundation                 0x15cb0 __CFSTRING_IS_CALLING_OUT_TO_AN_OBJECT_FORMAT_ARGUMENT_WITH_LOCALE__ + 28
7  CoreFoundation                 0x8c4c __CFStringAppendFormatCore + 9968
8  CoreFoundation                 0x122e4 _CFStringCreateWithFormatAndArgumentsReturningMetadata + 184
9  CoreFoundation                 0x12398 _CFStringCreateWithFormatAndArgumentsAux2 + 44
10 Foundation                     0x9b2bb0 +[NSString stringWithFormat:] + 68
11 mParticle_Apple_SDK            0x3b7c8 -[MPUpload description] + 172
12 mParticle_Apple_SDK            0x232c4 -[MPPersistenceController_PRIVATE saveUpload:] + 1472
13 mParticle_Apple_SDK            0x94d1c -[MPUploadBuilder build:] + 3488
14 mParticle_Apple_SDK            0x6e30c __55-[MPBackendController_PRIVATE prepareBatchesForUpload:]_block_invoke_4 + 548
```

* MPListenerController is not required in this scenario.
Removing MPListenerController

(cherry picked from commit 91c0c5d)

* fix: Thread-safe access to currentUser to prevent crash during kit replay (#576)

The currentUser property on MPIdentityApi was nonatomic with no
synchronization, but written on messageQueue (via identity responses)
and read on the main queue (via replayQueuedItems -> isActiveAndNotDisabled).
Stacktrace
```
0  libobjc.A.dylib                0x144c objc_retain_x0
1  libobjc.A.dylib                0x144c objc_retain
2  mParticle_Apple_SDK            0x392f8 -[MPIdentityApi currentUser] + 32
3  mParticle_Apple_SDK            0x8a078 -[MPKitContainer_PRIVATE isActiveAndNotDisabled:] + 208
4  mParticle_Apple_SDK            0x89ed0 -[MPKitContainer_PRIVATE activeKitsRegistry] + 208
5  mParticle_Apple_SDK            0x8ccc0 -[MPKitContainer_PRIVATE forwardSDKCall:event:parameters:messageType:userInfo:] + 124
6  mParticle_Apple_SDK            0x7ed3c __43-[MPKitContainer_PRIVATE replayQueuedItems]_block_invoke_3 + 88
```

(cherry picked from commit a3ba57e)

* fix: Add Brackets Thread Safety Tests (#573)

(cherry picked from commit 0d831cc)

* fix: background expiration race (#577)

* fix: background expiration race

* edit tests

* remove additional mock interface

(cherry picked from commit 9d97bd3)

* fix: Guarantee UserDefaults Thread Safety (#580)

fix: Guarantee UserDefsults Thread Safety
(cherry picked from commit 7baa7b4)

* fix: App crash when JSON serialization of upload dictionary (#579)

* fix: App crash when JSON serialization of upload dictionary

Prevent heap corruption from concurrent mutation of shared mutable objects during JSON serialization.
Added a mechanism to create a deep immutable copy of JSON-compatible objects, ensuring thread safety and preventing heap corruption during serialization.
Invalid entries are logged and dropped.
Stacktrace
```
0  libsystem_malloc.dylib         0x30a0 _xzm_xzone_malloc_freelist_outlined + 864
1  Foundation                     0xa2e854 -[_NSJSONWriter resizeTemporaryBuffer:] + 104
2  Foundation                     0x114f8 _convertJSONString + 148
3  Foundation                     0x1138c _writeJSONString + 84
4  Foundation                     0x94628 ___writeJSONObject_block_invoke + 412
5  CoreFoundation                 0x12044 __NSDICTIONARY_IS_CALLING_OUT_TO_A_BLOCK__ + 24
6  CoreFoundation                 0x19fb40 -[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:] + 288
7  Foundation                     0x97c54 _writeJSONObject + 512
8  Foundation                     0x94628 ___writeJSONObject_block_invoke + 412
9  CoreFoundation                 0x12044 __NSDICTIONARY_IS_CALLING_OUT_TO_A_BLOCK__ + 24
10 CoreFoundation                 0x19fb40 -[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:] + 288
11 Foundation                     0x97c54 _writeJSONObject + 512
12 Foundation                     0xa2e70c -[_NSJSONWriter dataWithRootObject:options:] + 104
13 Foundation                     0xa2f6b8 +[NSJSONSerialization dataWithJSONObject:options:error:] + 112
14 mParticle_Apple_SDK            0x3b480 -[MPUpload initWithSessionId:uploadDictionary:dataPlanId:dataPlanVersion:uploadSettings:] + 140
15 mParticle_Apple_SDK            0x94cfc -[MPUploadBuilder build:] + 3456
16 mParticle_Apple_SDK            0x6e30c __55-[MPBackendController_PRIVATE prepareBatchesForUpload:]_block_invoke_4 + 548
```

* refactor: rework the fix to cover SDKE-906

Stacktrace
```
0  libsystem_malloc.dylib         0x35104 _xzm_xzone_malloc_from_tiny_chunk.cold.1 + 36
1  libsystem_malloc.dylib         0x1d28 _xzm_xzone_malloc_from_tiny_chunk + 612
2  libsystem_malloc.dylib         0x164c _xzm_xzone_find_and_malloc_from_tiny_chunk + 112
3  libsystem_malloc.dylib         0x1e84 _xzm_xzone_malloc_tiny_outlined + 312
4  CoreFoundation                 0x3566c __CFBinaryPlistWriteOrPresize + 292
5  Foundation                     0x5ed80 -[NSKeyedArchiver finishEncoding] + 640
6  Foundation                     0x2c39e4 +[NSKeyedArchiver archivedDataWithRootObject:] + 112
7  mParticle_Apple_SDK            0x23234 -[MPPersistenceController_PRIVATE saveUpload:] + 1284
8  mParticle_Apple_SDK            0x95154 -[MPUploadBuilder build:] + 3488
9  mParticle_Apple_SDK            0x6e744 __55-[MPBackendController_PRIVATE prepareBatchesForUpload:]_block_invoke_4 + 548
10 CoreFoundation                 0x1ce98 __NSDICTIONARY_IS_CALLING_OUT_TO_A_BLOCK__ + 24
11 CoreFoundation                 0x1d078 -[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:] + 288
12 mParticle_Apple_SDK            0x6e4e0 __55-[MPBackendController_PRIVATE prepareBatchesForUpload:]_block_invoke_3 + 172
13 CoreFoundation                 0x1ce98 __NSDICTIONARY_IS_CALLING_OUT_TO_A_BLOCK__ + 24
14 CoreFoundation                 0x1d078 -[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:] + 288
15 mParticle_Apple_SDK            0x6e3fc __55-[MPBackendController_PRIVATE prepareBatchesForUpload:]_block_invoke_2 + 164
```

(cherry picked from commit a5e1960)

* fix: Add Try/Catch to File Write (#581)

(cherry picked from commit 18045c9)

* chore: Cleanup Release Actions (#570)

(cherry picked from commit aee96c4)

* fix: Potential MPURLRequestBuilder crash (#578)

* fix: Potential crash in MPURLRequestBuilder

* Add validation for API key and secret

* Allow nil secrets and key

There's logic allowing network requests without the header x-mp-signature

(cherry picked from commit 70c0076)

* fix: endSessionIfTimedOut race condition (#582)

* fix: endSessionIfTimedOut race condition

* add test

(cherry picked from commit b2eb508)

* fix: PreferredLanguages may be empty (#583)

fix: array may be empty
(cherry picked from commit 5a538c3)

* fix: MPNetworkCommunication background task (#584)

* fix: Dispatch MPNetworkCommunication main thread

* Update MPBackendControllerTests.m

(cherry picked from commit dfab795)

* test: fix endSessionIfTimedOut failing tests (#585)

* test: fix endSessionIfTimedOut failing tests

* adjust fix for message queue mismatch

* add test for automaticSessionTracking being disabled

(cherry picked from commit 42571ed)

* ci: Reorder S3 upload to after branch push in release workflow (#586)

* Reordered the release workflow steps so "Upload xcframeworks to S3" runs after "Push release branch"
* New step order: Commit version changes → Push release branch → Upload to S3 → Create Pull Request
* This ensures the irreversible S3 upload only happens after the git state is successfully committed and pushed, preventing version numbers from being burned on failed releases
* Removed trunk fmt step from the workflow since it's no longer needed
* Rewrote Scripts/update_mapping_versions.sh to use sed for in-place string replacement instead of jq. This preserves the original file formatting and eliminates the need for post-processing with prettier or trunk fmt.

(cherry picked from commit 02cb9f0)

* chore: Release v8.43.1 (#588)

chore: (release) 8.43.1

Updates version to 8.43.1 in:
- CHANGELOG.md
- Framework/Info.plist
- Package.swift
- mParticle-Apple-SDK.podspec
- mParticle-Apple-SDK/MPConstants.swift
- mParticle-Apple-SDK/MPIConstants.m
- mParticle_Apple_SDK.json
- IntegrationTests/wiremock-recordings/mappings/*.json

(cherry picked from commit b0a3d00)

* chore: Add AGENTS file (#590)

(cherry picked from commit 0d3d99b)

---------

Co-authored-by: James Newman <james.newman@rokt.com>
Co-authored-by: Thomson Thomas <125323226+thomson-t@users.noreply.github.com>
Co-authored-by: Nickolas Dimitrakas <nickolas.dimitrakas@rokt.com>
Co-authored-by: denischilik <denis.chilik@rokt.com>
Co-authored-by: mParticle Bot User <developers@mparticle.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants