Skip to content

Instantly share code, notes, and snippets.

@ccgus
Created February 26, 2012 01:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccgus/1912044 to your computer and use it in GitHub Desktop.
Save ccgus/1912044 to your computer and use it in GitHub Desktop.
CI Stack Crasher
#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