Paul Beusterien 1 рік тому
батько
коміт
560777f572

+ 3 - 0
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.
 

+ 9 - 2
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];