Skip to content

Commit

Permalink
Use secure NSKeyedArchiving for color preferences.
Browse files Browse the repository at this point in the history
  • Loading branch information
MaddTheSane committed Apr 11, 2023
1 parent f9b6f39 commit 805d2c6
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Classes/Session/TSSTPageView.m
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ - (void)drawRect:(NSRect)aRect
NSGraphicsContext *gcontext = NSGraphicsContext.currentContext;
[gcontext saveGraphicsState];
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
NSColor * color = [NSKeyedUnarchiver unarchiveObjectWithData: [defaults valueForKey: TSSTBackgroundColor]];
NSColor * color = [NSKeyedUnarchiver unarchivedObjectOfClass:[NSColor class] fromData:[defaults valueForKey: TSSTBackgroundColor] error:NULL];
self.layer.backgroundColor = [color CGColor];

NSData *firstPageImageData = firstPageImage.TIFFRepresentation;
Expand Down
12 changes: 6 additions & 6 deletions Classes/Session/TSSTSessionWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
}
else if([keyPath isEqualToString: TSSTBackgroundColor])
{
NSColor * color = [NSKeyedUnarchiver unarchiveObjectWithData: [defaults valueForKey: TSSTBackgroundColor]];
NSColor * color = [NSKeyedUnarchiver unarchivedObjectOfClass:[NSColor class] fromData:[defaults valueForKey: TSSTBackgroundColor] error:NULL];
[pageScrollView setBackgroundColor: color];
}
else if([keyPath isEqualToString: TSSTStatusbarVisible])
Expand Down Expand Up @@ -1077,15 +1077,15 @@ - (void)restoreSession
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
NSInteger loupeDiameter = [defaults integerForKey: TSSTLoupeDiameter];
[loupeWindow setFrame:NSMakeRect(0,0, loupeDiameter, loupeDiameter) display: NO];
NSColor * color = [NSKeyedUnarchiver unarchiveObjectWithData: [defaults valueForKey: TSSTBackgroundColor]];
NSColor * color = [NSKeyedUnarchiver unarchivedObjectOfClass:[NSColor class] fromData:[defaults valueForKey: TSSTBackgroundColor] error:NULL];
[pageScrollView setBackgroundColor: color];
[pageView setRotation: session.rotation];
NSValue * positionValue;
NSData * posData = [session valueForKey: @"position"];

if(posData)
{
positionValue = [NSKeyedUnarchiver unarchiveObjectWithData: posData];
positionValue = [NSKeyedUnarchiver unarchivedObjectOfClass:[NSValue class] fromData:posData error:NULL];
if (!positionValue) {
positionValue = [NSUnarchiver unarchiveObjectWithData: posData];
}
Expand All @@ -1094,7 +1094,7 @@ - (void)restoreSession
if(scrollData)
{
[self setShouldCascadeWindows: NO];
positionValue = [NSKeyedUnarchiver unarchiveObjectWithData: scrollData];
positionValue = [NSKeyedUnarchiver unarchivedObjectOfClass: [NSValue class] fromData: scrollData error: NULL];
if (!positionValue) {
positionValue = [NSUnarchiver unarchiveObjectWithData: scrollData];
}
Expand Down Expand Up @@ -1364,11 +1364,11 @@ - (void)updateSessionObject
if(![[self window] isFullscreen])
{
NSValue * postionValue = [NSValue valueWithRect: [[self window] frame]];
NSData * posData = [NSKeyedArchiver archivedDataWithRootObject: postionValue];
NSData * posData = [NSKeyedArchiver archivedDataWithRootObject: postionValue requiringSecureCoding: YES error: NULL];
session.position = posData;

postionValue = [NSValue valueWithPoint: [[pageView enclosingScrollView] documentVisibleRect].origin];
posData = [NSKeyedArchiver archivedDataWithRootObject: postionValue];
posData = [NSKeyedArchiver archivedDataWithRootObject: postionValue requiringSecureCoding: YES error: NULL];
session.scrollPosition = posData;
}
else
Expand Down
6 changes: 3 additions & 3 deletions Classes/SimpleComicAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ + (void)initialize
TSSTPageScaleOptions: @1,
TSSTTwoPageSpread: @YES,
TSSTScrollersVisible: @YES,
TSSTBackgroundColor: [NSKeyedArchiver archivedDataWithRootObject: [NSColor whiteColor]],
TSSTBackgroundColor: [NSKeyedArchiver archivedDataWithRootObject: [NSColor whiteColor] requiringSecureCoding: YES error: NULL],
TSSTConstrainScale: @YES,
TSSTWindowAutoResize: @YES,
TSSTEnableSwipe: @NO,
Expand All @@ -218,10 +218,10 @@ + (void)initialize
[defaults registerDefaults: standardDefaults];
NSData *colorData = [defaults dataForKey: TSSTBackgroundColor];
// Convert old NSArchiver color key to NSKeyedArchiver, if needed
if ([NSKeyedUnarchiver unarchiveObjectWithData: colorData] == nil) {
if ([NSKeyedUnarchiver unarchivedObjectOfClass:[NSColor class] fromData:colorData error:NULL] == nil) {
NSColor *newColor = [NSUnarchiver unarchiveObjectWithData: colorData];
if (newColor && [newColor isKindOfClass: [NSColor class]]) {
NSData *newKey = [NSKeyedArchiver archivedDataWithRootObject: newColor];
NSData *newKey = [NSKeyedArchiver archivedDataWithRootObject: newColor requiringSecureCoding:YES error:NULL];
[defaults setObject: newKey forKey: TSSTBackgroundColor];
} else {
//shrug
Expand Down
13 changes: 6 additions & 7 deletions Resources/Base.lproj/Preferences.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="20037" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21701" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="20037"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21701"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand All @@ -18,7 +17,7 @@
<windowStyleMask key="styleMask" titled="YES" closable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="140" y="154" width="320" height="270"/>
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1415"/>
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="875"/>
<view key="contentView" id="247">
<rect key="frame" x="0.0" y="0.0" width="320" height="282"/>
<autoresizingMask key="autoresizingMask"/>
Expand Down Expand Up @@ -87,16 +86,16 @@
</textFieldCell>
</textField>
<colorWell translatesAutoresizingMaskIntoConstraints="NO" id="238">
<rect key="frame" x="14" y="244" width="20" height="20"/>
<rect key="frame" x="11" y="242" width="26" height="24"/>
<constraints>
<constraint firstAttribute="width" constant="20" id="LcY-29-3Cg"/>
<constraint firstAttribute="height" constant="20" id="oZD-F6-H5Q"/>
</constraints>
<color key="color" red="0.058130499000000002" green="0.055541898999999999" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<connections>
<binding destination="42" name="value" keyPath="values.pageBackgroundColor" id="242">
<binding destination="42" name="value" keyPath="values.pageBackgroundColor" id="FDp-gK-LPg">
<dictionary key="options">
<string key="NSValueTransformerName">NSKeyedUnarchiveFromData</string>
<string key="NSValueTransformerName">NSSecureUnarchiveFromDataTransformer</string>
</dictionary>
</binding>
</connections>
Expand Down
2 changes: 1 addition & 1 deletion Vendor/XADMaster

0 comments on commit 805d2c6

Please sign in to comment.