6

I have the following problem while unarchiving a file, which contains an xml string.

It crashes at the following line:

NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];

'data' (27580 bytes) comes from:

NSMutableData *data = [NSData dataWithContentsOfURL:url];

And the crash i got:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[NSKeyedUnarchiver initForReadingWithData:]: incomprehensible archive (0x62, 0x70, 0x6c, 0x69, 0x73, 0x74, 0x30, 0x30)'

The file was created that way:

NSMutableData *data = [[NSMutableData alloc] init];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];

NSData *project = [ProjectToXML convertProject:SelectedProject];

[archiver encodeObject:project forKey:kProjectKey];
[archiver finishEncoding];

'convertProject:' does basically create an NSMutableString with the xml content and converts it to NSData that way ('encoding' is utf-8):

[xmlString dataUsingEncoding: CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((__bridge CFStringRef)encoding)) allowLossyConversion:NO];
Loxone Thomas
  • 133
  • 2
  • 6
  • How did you create that file? – borrrden Nov 21 '13 at 10:07
  • Can you unarchive the data directly after archiving it (i.e. without saving to a file first)? – borrrden Nov 22 '13 at 01:07
  • Yes! It worked all the time, only with one specific file I got this error. Maybe the size of the data is too big? – Loxone Thomas Nov 22 '13 at 07:10
  • Perhaps that one file got corrupted then. If it crashed during write, etc, that could happen. – borrrden Nov 22 '13 at 07:36
  • No, it couldnt have crashed, because that file was sent via mail after creating. Any idea how I can unarchive this file anyway? – Loxone Thomas Nov 22 '13 at 09:55
  • If you can't unarchive it that way, then I doubt you can unarchive it at all without analyzing the data with a hex editor. – borrrden Nov 22 '13 at 10:03
  • 3
    I had the same issue with the same error: "[NSKeyedUnarchiver initForReadingWithData:]: incomprehensible archive", and it only crashed on iOS 8. The problem was that when the data was archiving, it was archived even object which was nil. Now I added a check if ([self lastLocation] != nil) { [[NSKeyedArchiver archivedDataWithRootObject:[self lastLocation]] writeToFile:LOC_CACHE_PATH atomically:YES]; } – Lily Sep 22 '14 at 14:05
  • @Lily, just to clarify - has this been fixed in iOS 9 and up? – Luke Dec 22 '16 at 18:54

0 Answers0