Skip to content

Commit 5909266

Browse files
authored
fix(🍏): prevent crash in ViewScreenshotService when image data is null (#3579)
When screenshotOfViewWithTag: is called on a view that cannot be rendered (e.g. it has a frame of {0,0}, is not currently visible, or the app is in the background), the UIGraphicsImageRenderer may return a valid UIImage object but with a NULL CGImage or empty data. Attempting to call CGDataProviderCopyData on a null provider, or subsequently CFDataGetLength on a null dataRef, results in a hard crash (typically EXC_BAD_ACCESS or CF_IS_OBJC inside CoreFoundation).
1 parent 1a865ab commit 5909266

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

‎packages/skia/apple/ViewScreenshotService.mm‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ - (instancetype)initWithUiManager:(RCTUIManager *)uiManager {
5050

5151
// Convert from UIImage -> CGImage -> SkImage
5252
CGImageRef cgImage = image.CGImage;
53+
if (!cgImage) {
54+
return nullptr;
55+
}
5356

5457
// Get some info about the image
5558
auto width = CGImageGetWidth(cgImage);
@@ -59,6 +62,9 @@ - (instancetype)initWithUiManager:(RCTUIManager *)uiManager {
5962
// Convert from UIImage -> SkImage, start by getting the pixels directly from
6063
// the CGImage:
6164
auto dataRef = CGDataProviderCopyData(CGImageGetDataProvider(cgImage));
65+
if (!dataRef) {
66+
return nullptr;
67+
}
6268
auto length = CFDataGetLength(dataRef);
6369
void *data = CFDataGetMutableBytePtr((CFMutableDataRef)dataRef);
6470

0 commit comments

Comments
 (0)