Re: Feeding NSUnarchiver bad data can cause crash
Re: Feeding NSUnarchiver bad data can cause crash
- Subject: Re: Feeding NSUnarchiver bad data can cause crash
- From: "Douglas A. Welton" <email@hidden>
- Date: Thu, 03 Jun 2004 11:10:43 -0400
on 6/3/04 9:00 AM, Jeremy Dronfield at email@hidden wrote:
>
Yes, I tried something like this before. My version (suited to the
>
particular case, where I'm passing the unarchiver decrypted data
>
retrieved from an encrypted property list) is this:
>
>
NS_DURING
>
theText = [NSUnarchiver unarchiveObjectWithData:plaintext]; // CRASH!!
>
NS_HANDLER
>
if ([[localException name] isEqualToString:NSMallocException])
>
NSLog(@"malloc exception");
>
theText = nil;
>
success = NO;
>
NS_ENDHANDLER
>
>
It doesn't work. The error isn't handled. This is why I lament the lack
>
of an ability to do something like, if ([plaintext canBeUnarchived])
>
or, if ([plaintext conformsToArchiving]).
Jeremy,
When you say, "it doesn't work" do you mean that an exception not thrown OR
do you mean that your code did not do what it was supposed to do? The code
I enclosed in my last e-mail is a snip from a working application, so I know
that what it does indeed work.
If you want a -canBeUnarchived: method, perhaps you might just try
implementing your own. Something like this should work...
- (BOOL)canBeUnarchived: (NSData *)Target_Data
{
id Archive;
NS_DURING
Archive = [NSUarchiver unarchiveObjectWithData: Target_Data]
return YES;
NS_HANDLER
return NO;
NS_ENDHANDLER
}
... note the standard disclaimers apply.
later,
douglas
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.