Repository: firebase/firebase-ios-sdk (language: cpp)

Issue:
NSGenericException in `InstrumentUploadTaskWithStreamedRequest`
### Description

Description
- 
Similar to https://github.com/firebase/firebase-ios-sdk/issues/11821, our crash rate started to increase and the crash stack trace is pointing to this function `InstrumentUploadTaskWithStreamedRequest`.

Sample of our Crash Stacktrace
-
```
Fatal Exception: NSGenericException
0  CoreFoundation                 0xecb28 __exceptionPreprocess
1  libobjc.A.dylib                0x2af78 objc_exception_throw
2  CFNetwork                      0xdce4 _CFNetworkSetHSTSStoragePath
3  FirebasePerformance            0x18870 __InstrumentUploadTaskWithStreamedRequest_block_invoke + 486 (FPRNSURLSessionInstrument.m:486)
4  FirebasePerformance            0x18870 __InstrumentUploadTaskWithStreamedRequest_block_invoke + 486 (FPRNSURLSessionInstrument.m:486)
5  NewRelic                       0x38348 NRMAOverride__uploadTaskWithStreamedRequest + 355 (NRMAURLSessionOverride.m:355)
6  NewRelic                       0x530fc -[NRMAHexUploader handledErroredRequest:] + 141 (NRMAHexUploader.m:141)
7  NewRelic                       0x52cfc -[NRMAHexUploader URLSession:task:didCompleteWithError:] + 107 (NRMAHexUploader.m:107)
8  NewRelic                       0x353e8 -[NRURLSessionTaskDelegateBase URLSession:task:didCompleteWithError:] + 74 (NRMAURLSessionTaskDelegateBase.m:74)
9  FirebasePerformance            0x15eb4 __InstrumentURLSessionTaskDidCompleteWithError_block_invoke + 61 (FPRNSURLSessionDelegateInstrument.m:61)
10 CFNetwork                      0x1598c _CFNetworkSetHSTSStoragePath
11 libdispatch.dylib              0x213c _dispatch_call_block_and_release
12 libdispatch.dylib              0x3dd4 _dispatch_client_callout
13 libdispatch.dylib              0xb400 _dispatch_lane_serial_drain
14 libdispatch.dylib              0xbf64 _dispatch_lane_invoke
15 libdispatch.dylib              0x16cb4 _dispatch_root_queue_drain_deferred_wlh
16 libdispatch.dylib              0x16528 _dispatch_workloop_worker_thread
17 libsystem_pthread.dylib        0x1f20 _pthread_wqthread
18 libsystem_pthread.dylib        0x1fc0 start_wqthread
```

### Reproducing the issue

_No response_

### Firebase SDK Version

10.24.0

### Xcode Version

15.3

### Installation Method

CocoaPods

### Firebase Product(s)

App Distribution, Crashlytics, Performance, Remote Config

### Targeted Platforms

iOS

### Relevant Log Output

_No response_

### If using Swift Package Manager, the project's Package.resolved

<!--- Look below for instructions on how to share your Package.resolved. --->

<details>
<summary>Expand <code>Package.resolved</code> snippet</summary>
<br>

```json

Replace this line with the contents of your Package.resolved.

```

</details>


### If using CocoaPods, the project's Podfile.lock

<!--- Look below for instructions on how to share your Podfile.lock. --->

<details>
<summary>Expand <code>Podfile.lock</code> snippet</summary>
<br>

```yml

Replace this line with the contents of your Podfile.lock!

```

</details>



Discussion / hints:
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
Hello @paulb777 ,

You provided a fix for other functions and mentioned in [this issue](https://github.com/firebase/firebase-ios-sdk/issues/11821) that the issue could still exist in this scope. 
`
The fix got deployed in the InstrumentUploadTaskWithRequestFromData function, but it looks like the same issue is still in InstrumentUploadTaskWithStreamedRequest.
`

Can you please take a look here?

Thank you. 

Fix patch:
diff --git a/FirebasePerformance/CHANGELOG.md b/FirebasePerformance/CHANGELOG.md
index 8ca612948e3..f814d7d6290 100644
--- a/FirebasePerformance/CHANGELOG.md
+++ b/FirebasePerformance/CHANGELOG.md
@@ -1,3 +1,6 @@
+# Unreleased
+- Fix Crash from InstrumentUploadTaskWithStreamedRequest (#12983).
+
 # 10.25.0
 - [changed] Removed usages of user defaults API to eliminate required reason impact.
 
diff --git a/FirebasePerformance/Sources/Instrumentation/Network/FPRNSURLSessionInstrument.m b/FirebasePerformance/Sources/Instrumentation/Network/FPRNSURLSessionInstrument.m
index 123d3cdb3e9..4951cbd5a03 100644
--- a/FirebasePerformance/Sources/Instrumentation/Network/FPRNSURLSessionInstrument.m
+++ b/FirebasePerformance/Sources/Instrumentation/Network/FPRNSURLSessionInstrument.m
@@ -482,8 +482,15 @@ void InstrumentUploadTaskWithStreamedRequest(FPRNSURLSessionInstrument *instrume
     if (!strongInstrument) {
       ThrowExceptionBecauseInstrumentHasBeenDeallocated(selector, instrumentor.instrumentedClass);
     }
-    typedef NSURLSessionUploadTask *(*OriginalImp)(id, SEL, NSURLRequest *);
-    NSURLSessionUploadTask *uploadTask = ((OriginalImp)currentIMP)(session, selector, request);
+    typedef NSURLSessionUploadTask *(*OriginalImp)(id, SEL, NSURLRequest *, NSData *);
+    // To avoid a runtime warning in Xcode 15, the given `URLRequest`
+    // should have a nil `HTTPBody`. To workaround this, the `HTTPBody` data is removed
+    // and requestData is replaced with it, if it bodyData was `nil`.
+    NSMutableURLRequest *requestWithoutHTTPBody = [request mutableCopy];
+    NSData *requestData = requestWithoutHTTPBody.HTTPBody;
+    requestWithoutHTTPBody.HTTPBody = nil;
+    NSURLSessionUploadTask *uploadTask =
+        ((OriginalImp)currentIMP)(session, selector, request, requestData);
     if (uploadTask.originalRequest) {
       FPRNetworkTrace *trace =
           [[FPRNetworkTrace alloc] initWithURLRequest:uploadTask.originalRequest];


Test patch: