Created
February 26, 2012 01:20
-
-
Save ccgus/1912044 to your computer and use it in GitHub Desktop.
CI Stack Crasher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import <QuartzCore/QuartzCore.h> | |
/* | |
This example will create around 15k stack frames on 10.7, which ends up crashing the process. | |
clang stackcrasher.m -o stackcrasher -framework Cocoa -framework QuartzCore -fobjc-arc | |
*/ | |
int main (int argc, const char * argv[]) | |
{ | |
@autoreleasepool { | |
int height = 10; | |
int max = 200; | |
int idx = 0; | |
NSURL *imageURL = [NSURL fileURLWithPath:@"/System/Library/Frameworks/AppKit.framework/Versions/C/Resources/NSTexturedFullScreenBackgroundColor.png"]; | |
CIImage *base = [CIImage imageWithContentsOfURL:imageURL]; | |
CIFilter *soFilter = [CIFilter filterWithName:@"CISourceOverCompositing"]; | |
while (idx < max) { | |
CIImage *a = [CIImage imageWithContentsOfURL:imageURL]; | |
[soFilter setValue:base forKey:kCIInputBackgroundImageKey]; | |
[soFilter setValue:a forKey:kCIInputImageKey]; | |
base = [soFilter valueForKey:kCIOutputImageKey]; | |
idx++; | |
} | |
CIContext *ctx = [CIContext new]; | |
CGImageRef cgimg = [ctx createCGImage:base fromRect:NSMakeRect(0, 0, max, height)]; | |
NSString *path = [NSTemporaryDirectory() stringByAppendingPathComponent:@"crasher.tiff"]; | |
CGImageDestinationRef imageDestination = CGImageDestinationCreateWithURL((__bridge CFURLRef)[NSURL fileURLWithPath:path], kUTTypeTIFF, 1, NULL); | |
CGImageDestinationAddImage(imageDestination, cgimg, (__bridge CFDictionaryRef)[NSDictionary dictionary]); | |
CGImageDestinationFinalize(imageDestination); | |
CFRelease(imageDestination); | |
CGImageRelease(cgimg); | |
system([[NSString stringWithFormat:@"open %@", path] UTF8String]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment