On 2011 Jul 29, at 19:07, Gwynne Raskind wrote:

> On Fri, Jul 29, 2011 at 21:48,  <wadesli...@mac.com> wrote:
>>> Granted that NSKeyedUnarchiver might have left some memory leaks or 
>>> partially uninitialized objects somewhere, but unarchiving an invalid 
>>> object should happen rarely if at all... and ordinarily my own code should 
>>> never get pointers to such objects, anyway.
>> Indeed there may be memory leaks, but that's a relatively benign side 
>> effect.  The security issues I alluded to earlier are a much greater concern 
>> in any case.
> 
> Can you be more specific about those side effects?

Well, for perfectionists, another side effect is that an exception will often 
log a turd to the system console.

I wrote some code a couple years ago to archive NSError objects, for later 
display by another process.  Formally, NSError conforms to NSCoding.  But in 
practice, it may contain unencodable objects it its userInfo, and if userInfo 
includes an underlying error created by someone else, all bets are off.

To work around this, I traverse the error's -userInfo, making a copy and 
checking each leaf for encodability with a @try{} around 
-archivedDataWithRootObject:.  If a leaf is not encodable, I replace it in the 
copy with its -description.  Then I create a new error using the encodable copy 
of userInfo and encode that.

If I @catch an error, besides using -description, I also log a message to 
console saying "Please ignore the above exception…".  Pretty bad.

On 2011 Jul 29, at 13:15, Jens Alfke wrote:

> Basically this would require a whole new API to encoding/decoding, where 
> everything took an NSError** parameter.  …  Exceptions Are Good, since you 
> don’t have to rip apart your API and add lots of extra parameters just to add 
> error handling.

Yes, I've been there and done that.  It's certainly within Apple's 
capabilities.  However, understanding the reasons given in this discussion for 
not wanting to mess with NSKeyedArchiver and NSKeyedUnarchiver, or provide new 
classes, I think these methods would make me happy:

+[NSKeyedArchiver isEncodeable:(id)object]
+[NSKeyedUnarchiver isAValidArchive:(NSData*)data]

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to