Revision: 15805
http://sourceforge.net/p/skim-app/code/15805
Author: hofman
Date: 2025-11-17 17:37:35 +0000 (Mon, 17 Nov 2025)
Log Message:
-----------
Use secure coding in skimnotes
Modified Paths:
--------------
trunk/SkimNotes/ReleaseNotes.rtf
trunk/SkimNotes/SKNDocument.m
trunk/SkimNotes/SKNUtilities.m
trunk/SkimNotes/skimnotes.m
Modified: trunk/SkimNotes/ReleaseNotes.rtf
===================================================================
--- trunk/SkimNotes/ReleaseNotes.rtf 2025-11-14 23:54:06 UTC (rev 15804)
+++ trunk/SkimNotes/ReleaseNotes.rtf 2025-11-17 17:37:35 UTC (rev 15805)
@@ -93,6 +93,7 @@
\ls1\ilvl0
\f1\b0 \cf0 {\listtext \uc0\u8226 }Use macros to define enums for better
Swift compatibility\
{\listtext \uc0\u8226 }Rename enum values for xattr writing options,
old ones are still available in ObjC\
+{\listtext \uc0\u8226 }Use secure coding\
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\pardirnatural\partightenfactor0
\cf0 \
Modified: trunk/SkimNotes/SKNDocument.m
===================================================================
--- trunk/SkimNotes/SKNDocument.m 2025-11-14 23:54:06 UTC (rev 15804)
+++ trunk/SkimNotes/SKNDocument.m 2025-11-17 17:37:35 UTC (rev 15805)
@@ -94,7 +94,7 @@
- (NSData *)dataOfType:(NSString *)docType error:(NSError **)outError {
NSData *data = nil;
if ([[NSWorkspace sharedWorkspace] type:SKNSkimNotesDocumentType
conformsToType:docType]) {
- data = [NSKeyedArchiver archivedDataWithRootObject:_notes];
+ data = [NSKeyedArchiver archivedDataWithRootObject:_notes
requiringSecureCoding:YES error:NULL];
}
if (data == nil && outError)
*outError = [NSError errorWithDomain:SKNDocumentErrorDomain code:0
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Unable
to save notes", @""), NSLocalizedDescriptionKey, nil]];
@@ -127,7 +127,7 @@
[ws type:docType conformsToType:SKNSkimNotesDocumentType]) {
data = [[SKNSkimReader sharedReader] SkimNotesAtURL:absoluteURL];
if (data) {
- @try { array = [NSKeyedUnarchiver unarchiveObjectWithData:data]; }
+ @try { array = [NSKeyedUnarchiver unarchivedObjectOfClasses:[NSSet
setWithObjects:[NSArray class], [NSDictionary class], [NSString class],
[NSNumber class], [NSData class], [NSColor class], [NSFont class],
[NSAttributedString class], [NSImage class], nil] fromData:data error:NULL]; }
@catch (id e) {}
if (array == nil)
array = [NSPropertyListSerialization propertyListWithData:data
options:NSPropertyListImmutable format:NULL error:NULL];
@@ -143,7 +143,7 @@
[ws type:docType conformsToType:SKNSkimNotesDocumentType]) {
data = [[SKNXPCSkimReader sharedReader] SkimNotesAtURL:absoluteURL];
if (data) {
- @try { array = [NSKeyedUnarchiver unarchiveObjectWithData:data]; }
+ @try { array = [NSKeyedUnarchiver unarchivedObjectOfClasses:[NSSet
setWithObjects:[NSArray class], [NSDictionary class], [NSString class],
[NSNumber class], [NSData class], [NSColor class], [NSFont class],
[NSAttributedString class], [NSImage class], nil] fromData:data error:NULL]; }
@catch (id e) {}
if (array == nil)
array = [NSPropertyListSerialization propertyListWithData:data
options:NSPropertyListImmutable format:NULL error:NULL];
@@ -158,7 +158,7 @@
[[SKNXPCSkimReader sharedReader] readSkimNotesAtURL:absoluteURL
reply:(NSData *data){
if (data) {
NSArray *arr = nil;
- @try { arr = [NSKeyedUnarchiver unarchiveObjectWithData:data];
}
+ @try { arr = [NSKeyedUnarchiver
unarchivedObjectOfClasses:[NSSet setWithObjects:[NSArray class], [NSDictionary
class], [NSString class], [NSNumber class], [NSData class], [NSColor class],
[NSFont class], [NSAttributedString class], [NSImage class], nil] fromData:data
error:NULL]; }
@catch (id e) {}
if (arr == nil)
arr = [NSPropertyListSerialization
propertyListWithData:data options:NSPropertyListImmutable format:NULL
error:NULL];
@@ -227,7 +227,7 @@
}
if (data) {
if ([data length]) {
- @try { array = [NSKeyedUnarchiver unarchiveObjectWithData:data]; }
+ @try { array = [NSKeyedUnarchiver unarchivedObjectOfClasses:[NSSet
setWithObjects:[NSArray class], [NSDictionary class], [NSString class],
[NSNumber class], [NSData class], [NSColor class], [NSFont class],
[NSAttributedString class], [NSImage class], nil] fromData:data error:NULL]; }
@catch (id e) {}
if (array == nil)
array = [NSPropertyListSerialization propertyListWithData:data
options:NSPropertyListImmutable format:NULL error:NULL];
Modified: trunk/SkimNotes/SKNUtilities.m
===================================================================
--- trunk/SkimNotes/SKNUtilities.m 2025-11-14 23:54:06 UTC (rev 15804)
+++ trunk/SkimNotes/SKNUtilities.m 2025-11-17 17:37:35 UTC (rev 15805)
@@ -59,8 +59,17 @@
#define SKNFont NSFont
#define SKNImage NSImage
+#if !defined(MAC_OS_X_VERSION_10_13) || MAC_OS_X_VERSION_MAX_ALLOWED <
MAC_OS_X_VERSION_10_13
+@interface NSKeyedArchiver (SKNHighSierradeclarations)
++ (NSData *)archivedDataWithRootObject:(id)object
requiringSecureCoding:(BOOL)requiresSecureCoding error:(NSError **)error;
+@end
+@interface NSKeyedUnarchiver (SKNHighSierradeclarations)
++ (id)unarchivedObjectOfClasses:(NSSet *)classes fromData:(NSData *)data
error:(NSError **)error;
+@end
#endif
+#endif
+
#define NOTE_PAGE_INDEX_KEY @"pageIndex"
#define NOTE_TYPE_KEY @"type"
#define NOTE_CONTENTS_KEY @"contents"
@@ -231,11 +240,21 @@
[data getBytes:&ch range:NSMakeRange(8, 1)];
ch >>= 4;
if (ch == 0xD) {
- @try { noteDicts = [NSKeyedUnarchiver unarchiveObjectWithData:data]; }
- @catch (id e) {}
+#if !defined(SKIMNOTES_PLATFORM_IOS)
+#if (!defined(MAC_OS_X_VERSION_10_13) || MAC_OS_X_VERSION_MIN_REQUIRED <
MAC_OS_X_VERSION_10_13)
+ if ([NSKeyedUnarchiver
respondsToSelector:@selector(unarchivedObjectOfClasses:fromData:error:)] == NO)
{
+ @try { noteDicts = [NSKeyedUnarchiver
unarchiveObjectWithData:data]; }
+ @catch (id e) {}
+ } else
+#endif
+ {
+ @try { noteDicts = [NSKeyedUnarchiver
unarchivedObjectOfClasses:[NSSet setWithObjects:[NSArray class], [NSDictionary
class], [NSString class], [NSNumber class], [NSData class], [NSColor class],
[NSFont class], [NSAttributedString class], [NSImage class], nil] fromData:data
error:NULL]; }
+ @catch (id e) {}
+ }
if ([noteDicts isKindOfClass:[NSArray class]] == NO) {
noteDicts = nil;
}
+#endif
} else {
noteDicts = [NSPropertyListSerialization propertyListWithData:data
options:NSPropertyListMutableContainers format:NULL error:NULL];
if ([noteDicts isKindOfClass:[NSArray class]] == NO) {
@@ -293,7 +312,11 @@
}
#if !defined(PDFKIT_PLATFORM_IOS)
if (asPlist == NO) {
- return [NSKeyedArchiver archivedDataWithRootObject:noteDicts];
+#if (!defined(MAC_OS_X_VERSION_10_13) || MAC_OS_X_VERSION_MIN_REQUIRED <
MAC_OS_X_VERSION_10_13)
+ if ([NSKeyedArchiver
respondsToSelector:@selector(archivedDataWithRootObject:requiringSecureCoding:error:)]
== NO)
+ return [NSKeyedArchiver archivedDataWithRootObject:noteDicts];
+#endif
+ return [NSKeyedArchiver archivedDataWithRootObject:noteDicts
requiringSecureCoding:YES error:NULL];
}
#endif
NSMutableArray *array = [[NSMutableArray alloc] init];
Modified: trunk/SkimNotes/skimnotes.m
===================================================================
--- trunk/SkimNotes/skimnotes.m 2025-11-14 23:54:06 UTC (rev 15804)
+++ trunk/SkimNotes/skimnotes.m 2025-11-17 17:37:35 UTC (rev 15805)
@@ -42,6 +42,15 @@
#import "SKNUtilities.h"
#import "SKNDefines.h"
+#if !defined(MAC_OS_X_VERSION_10_13) || MAC_OS_X_VERSION_MAX_ALLOWED <
MAC_OS_X_VERSION_10_13
+@interface NSKeyedArchiver (SKNHighSierradeclarations)
++ (NSData *)archivedDataWithRootObject:(id)object
requiringSecureCoding:(BOOL)requiresSecureCoding error:(NSError **)error;
+@end
+@interface NSKeyedUnarchiver (SKNHighSierradeclarations)
++ (id)unarchivedObjectOfClasses:(NSSet *)classes fromData:(NSData *)data
error:(NSError **)error;
+@end
+#endif
+
static char *usageStr = "Usage:\n"
" skimnotes get [-format skim|archive|plist|text|rtf]
PDF_FILE [NOTES_FILE|-]\n"
" skimnotes set [-s|-n] PDF_FILE [SKIM_FILE|-]
[TEXT_FILE] [RTF_FILE]\n"
@@ -564,8 +573,16 @@
if (data) {
NSArray *inNotes = nil;
BOOL isPlist = NO;
- @try { inNotes = [NSKeyedUnarchiver
unarchiveObjectWithData:data]; }
- @catch (id e) {}
+#if (!defined(MAC_OS_X_VERSION_10_13) || MAC_OS_X_VERSION_MIN_REQUIRED <
MAC_OS_X_VERSION_10_13)
+ if ([NSKeyedUnarchiver
respondsToSelector:@selector(unarchivedObjectOfClasses:fromData:error:)] == NO)
{
+ @try { inNotes = [NSKeyedUnarchiver
unarchiveObjectWithData:data]; }
+ @catch (id e) {}
+ } else
+#endif
+ {
+ @try { inNotes = [NSKeyedUnarchiver
unarchivedObjectOfClasses:[NSSet setWithObjects:[NSArray class], [NSDictionary
class], [NSString class], [NSNumber class], [NSData class], [NSColor class],
[NSFont class], [NSAttributedString class], [NSImage class], nil] fromData:data
error:NULL]; }
+ @catch (id e) {}
+ }
if (inNotes == nil) {
inNotes = [NSPropertyListSerialization
propertyListWithData:data options:NSPropertyListImmutable format:NULL
error:NULL];
isPlist = YES;
@@ -586,10 +603,16 @@
[outNotes addObject:inNote];
}
}
- if (isPlist)
+ if (isPlist) {
data = [NSPropertyListSerialization
dataWithPropertyList:outNotes format:NSPropertyListBinaryFormat_v1_0 options:0
error:NULL];
- else
- data = [NSKeyedArchiver
archivedDataWithRootObject:outNotes];
+ } else {
+#if (!defined(MAC_OS_X_VERSION_10_13) || MAC_OS_X_VERSION_MIN_REQUIRED <
MAC_OS_X_VERSION_10_13)
+ if ([NSKeyedArchiver
respondsToSelector:@selector(archivedDataWithRootObject:requiringSecureCoding:error:)]
== NO)
+ data = [NSKeyedArchiver
archivedDataWithRootObject:noteDicts];
+ else
+#endif
+ data = [NSKeyedArchiver
archivedDataWithRootObject:outNotes requiringSecureCoding:YES error:NULL];
+ }
if (data) {
if ([outPath isEqualToString:STD_IN_OUT_FILE]) {
[(NSFileHandle *)[NSFileHandle
fileHandleWithStandardOutput] writeData:data];
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit