Revision: 9762
          http://sourceforge.net/p/skim-app/code/9762
Author:   hofman
Date:     2018-04-12 17:43:34 +0000 (Thu, 12 Apr 2018)
Log Message:
-----------
Check return value from unarchiving and return more useful error

Modified Paths:
--------------
    trunk/SkimNotes/Dutch.lproj/SkimNotes.strings
    trunk/SkimNotes/English.lproj/SkimNotes.strings
    trunk/SkimNotes/French.lproj/SkimNotes.strings
    trunk/SkimNotes/German.lproj/SkimNotes.strings
    trunk/SkimNotes/Italian.lproj/SkimNotes.strings
    trunk/SkimNotes/Japanese.lproj/SkimNotes.strings
    trunk/SkimNotes/NSFileManager_SKNExtensions.m
    trunk/SkimNotes/SKNExtendedAttributeManager.h
    trunk/SkimNotes/Spanish.lproj/SkimNotes.strings
    trunk/SkimNotes/pl.lproj/SkimNotes.strings
    trunk/SkimNotes/ru.lproj/SkimNotes.strings
    trunk/SkimNotes/zh_CN.lproj/SkimNotes.strings
    trunk/SkimNotes/zh_TW.lproj/SkimNotes.strings

Modified: trunk/SkimNotes/Dutch.lproj/SkimNotes.strings
===================================================================
(Binary files differ)

Modified: trunk/SkimNotes/English.lproj/SkimNotes.strings
===================================================================
(Binary files differ)

Modified: trunk/SkimNotes/French.lproj/SkimNotes.strings
===================================================================
(Binary files differ)

Modified: trunk/SkimNotes/German.lproj/SkimNotes.strings
===================================================================
(Binary files differ)

Modified: trunk/SkimNotes/Italian.lproj/SkimNotes.strings
===================================================================
(Binary files differ)

Modified: trunk/SkimNotes/Japanese.lproj/SkimNotes.strings
===================================================================
(Binary files differ)

Modified: trunk/SkimNotes/NSFileManager_SKNExtensions.m
===================================================================
--- trunk/SkimNotes/NSFileManager_SKNExtensions.m       2018-04-12 17:26:48 UTC 
(rev 9761)
+++ trunk/SkimNotes/NSFileManager_SKNExtensions.m       2018-04-12 17:43:34 UTC 
(rev 9762)
@@ -102,6 +102,10 @@
         if ([data length]) {
             @try { notes = [NSKeyedUnarchiver unarchiveObjectWithData:data]; }
             @catch (id e) {}
+            if ([notes isKindOfClass:[NSArray class]] == NO) {
+                notes = nil;
+                error = [NSError errorWithDomain:SKNSkimNotesErrorDomain 
code:SKNInvalidDataError userInfo:[NSDictionary 
dictionaryWithObjectsAndKeys:SKNLocalizedString(@"Invalid data.", @"Error 
description"), NSLocalizedDescriptionKey, nil]];
+            }
         } else if (data || ([[error domain] 
isEqualToString:NSPOSIXErrorDomain] && [error code] == ENOATTR)) {
             notes = [NSArray array];
         }
@@ -118,7 +122,10 @@
     if ([aURL isFileURL]) {
         string = [[SKNExtendedAttributeManager sharedManager] 
propertyListFromExtendedAttributeNamed:SKIM_TEXT_NOTES_KEY atPath:[aURL path] 
traverseLink:YES error:&error];
         
-        if (string == nil && [[error domain] 
isEqualToString:NSPOSIXErrorDomain] && [error code] == ENOATTR)
+        if ([string isKindOfClass:[NSString class]] == NO) {
+            string = nil;
+            error = [NSError errorWithDomain:SKNSkimNotesErrorDomain 
code:SKNInvalidDataError userInfo:[NSDictionary 
dictionaryWithObjectsAndKeys:SKNLocalizedString(@"Invalid data.", @"Error 
description"), NSLocalizedDescriptionKey, nil]];
+        } else if (string == nil && [[error domain] 
isEqualToString:NSPOSIXErrorDomain] && [error code] == ENOATTR)
             string = [NSString string];
     }
     if (string == nil && outError) 
@@ -154,6 +161,10 @@
         if ([data length]) {
             @try { notes = [NSKeyedUnarchiver unarchiveObjectWithData:data]; }
             @catch (id e) {}
+            if ([notes isKindOfClass:[NSArray class]] == NO) {
+                notes = nil;
+                error = [NSError errorWithDomain:SKNSkimNotesErrorDomain 
code:SKNInvalidDataError userInfo:[NSDictionary 
dictionaryWithObjectsAndKeys:SKNLocalizedString(@"Invalid data.", @"Error 
description"), NSLocalizedDescriptionKey, nil]];
+            }
         } else if (data || skimFileURL == nil) {
             notes = [NSArray array];
         }
@@ -211,6 +222,10 @@
         if ([data length]) {
             @try { notes = [NSKeyedUnarchiver unarchiveObjectWithData:data]; }
             @catch (id e) {}
+            if ([notes isKindOfClass:[NSArray class]] == NO) {
+                notes = nil;
+                error = [NSError errorWithDomain:SKNSkimNotesErrorDomain 
code:SKNInvalidDataError userInfo:[NSDictionary 
dictionaryWithObjectsAndKeys:SKNLocalizedString(@"Invalid data.", @"Error 
description"), NSLocalizedDescriptionKey, nil]];
+            }
         } else if (data) {
             notes = [NSArray array];
         }

Modified: trunk/SkimNotes/SKNExtendedAttributeManager.h
===================================================================
--- trunk/SkimNotes/SKNExtendedAttributeManager.h       2018-04-12 17:26:48 UTC 
(rev 9761)
+++ trunk/SkimNotes/SKNExtendedAttributeManager.h       2018-04-12 17:43:34 UTC 
(rev 9762)
@@ -75,11 +75,13 @@
     @constant    SKNReassembleAttributeFailedError  Fragments could not be 
reassembled to a combined value.
     @constant    SKNPlistSerializationFailedError   Property list 
serialization failed. Uses the description from NSPropertyListSerialization.
     @constant    SKNPlistDeserializationFailedError Property list 
deserialization failed. Uses the description from NSPropertyListSerialization.
+    @constant    SKNInvalidDataError                The data that was found 
was not valid.
 */
 enum {
     SKNReassembleAttributeFailedError  = 1,
     SKNPlistSerializationFailedError   = 2,
-    SKNPlistDeserializationFailedError = 3
+    SKNPlistDeserializationFailedError = 3,
+    SKNInvalidDataError = 4
 };
 
 /*!

Modified: trunk/SkimNotes/Spanish.lproj/SkimNotes.strings
===================================================================
(Binary files differ)

Modified: trunk/SkimNotes/pl.lproj/SkimNotes.strings
===================================================================
(Binary files differ)

Modified: trunk/SkimNotes/ru.lproj/SkimNotes.strings
===================================================================
(Binary files differ)

Modified: trunk/SkimNotes/zh_CN.lproj/SkimNotes.strings
===================================================================
(Binary files differ)

Modified: trunk/SkimNotes/zh_TW.lproj/SkimNotes.strings
===================================================================
(Binary files differ)

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Skim-app-commit mailing list
Skim-app-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to