App terminated to memory issues when performing CGImageDestinationFinalize on large images

Originator:bunny
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 https://openradar.appspot.com/31811274 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)
        CFRelease(imageSource);
    
    if (UTI)
        CFRelease(UTI);
    if (destination)
        CFRelease(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 
https://drive.google.com/file/d/16JlUmhNQZEl-I0tdupjDiNm4Ff-38EvO/view?usp=sharing

Best regards,
Bunny

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com 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!