App terminated to memory issues when performing CGImageDestinationFinalize on large images

Number:rdar://FB9997888 Date Originated:
Status: Resolved:
Product:iPhone 12 mini Product Version:iOS 15.0.2
Classification:Crash Reproducible:Always
Hi, there

This radar is similar to with some update about iOS system and sample image.

I use Image I/O of extremely large size (35433 × 7323) pixels in application is terminates due to memory issue.

Steps to Reproduce

- (NSData *) combineImgData:(NSData *)imageData
               withExifData:(NSDictionary *)exifData
    if (imageData == NULL || exifData == NULL) {
        // Error loading image
        return NULL;
    CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL);
    if (imageSource == NULL) {
        // Error loading image
       return NULL;
    // this is the type of image (e.g., public.jpeg)
    CFStringRef UTI = CGImageSourceGetType(imageSource);
    // create a new data object and write the new image into it
    NSMutableData *dest_data = [NSMutableData data];
    CGImageDestinationRef destination =
    CGImageDestinationCreateWithData((__bridge CFMutableDataRef)dest_data, UTI, 1, NULL);
    if (!destination) {
        LoggerCameraRollHelper(4, @"Error: Could not create image destination");
        return NULL;
    CGImageDestinationSetProperties(destination, NULL);
    // add the image contained in the image source to the destination, overidding the old metadata with our modified metadata
    CGImageDestinationAddImageFromSource(destination, imageSource, 0, (__bridge CFDictionaryRef) exifData);

    BOOL success = NO;
    success = CGImageDestinationFinalize(destination);
    if (!success) {
        LoggerCameraRollHelper(4, @"Error: Could not create data from image destination");
    if (imageSource)
    if (UTI)
    if (destination)
    return dest_data;

Expected Results
CGImageDestinationFinalize either succeeds and creates output image or returns nil in case of failure (for example, for large images).

Actual Results
memory issue always happen in CGImageDestinationFinalize 

I had uploaded the file to

Best regards,


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!