]> granicus.if.org Git - handbrake/commitdiff
MacGui: enable NSSecureCoding for the queue file.
authorDamiano Galassi <damiog@gmail.com>
Tue, 27 Dec 2016 10:53:11 +0000 (11:53 +0100)
committerDamiano Galassi <damiog@gmail.com>
Tue, 27 Dec 2016 10:53:11 +0000 (11:53 +0100)
13 files changed:
macosx/HBAudio.m
macosx/HBAudioDefaults.m
macosx/HBChapter.h
macosx/HBCodingUtilities.h
macosx/HBCodingUtilities.m
macosx/HBDistributedArray.h
macosx/HBDistributedArray.m
macosx/HBJob.m
macosx/HBPictureHUDController.h
macosx/HBQueueController.m
macosx/HBSubtitles.m
macosx/HBTitle.m
macosx/HBVideo.m

index 1faae116eee4c722abeba20c3a8bdfd78e7b8d58..be7df2465bc2d0a6ddbacdee029ad19f3603bb99 100644 (file)
@@ -285,8 +285,8 @@ NSString *HBAudioChangedNotification = @"HBAudioChangedNotification";
     self = [super init];
 
     decodeInt(_container);
-    decodeObject(_sourceTracks, NSMutableArray);
-    decodeObject(_tracks, NSMutableArray);
+    decodeCollectionOfObjects(_sourceTracks, NSArray, NSDictionary);
+    decodeCollectionOfObjects(_tracks, NSMutableArray, HBAudioTrack);
 
     for (HBAudioTrack *track in _tracks)
     {
index 127e2a47a4e9af11e0b50c6f61be12364478621d..204d13967eb3ae60c8c4a63437b6d5e845f831e6 100644 (file)
     decodeInteger(_trackSelectionBehavior);
     decodeObject(_trackSelectionLanguages, NSMutableArray);
 
-    decodeObject(_tracksArray, NSMutableArray);
+    decodeCollectionOfObjects(_tracksArray, NSMutableArray, HBAudioTrackPreset);
 
     decodeBool(_allowAACPassthru);
     decodeBool(_allowAC3Passthru);
index bef15d599f03bf4da19c45d37305827a9d10b03a..070a0f53d4e9eeee6741c7f2959c0829f2bfaad7 100644 (file)
@@ -12,7 +12,7 @@ NS_ASSUME_NONNULL_BEGIN
 
 - (instancetype)initWithTitle:(NSString *)title index:(NSUInteger)idx duration:(uint64_t)duration NS_DESIGNATED_INITIALIZER;
 
-@property (nonatomic, readwrite) NSString *title;
+@property (nonatomic, readwrite, copy) NSString *title;
 @property (nonatomic, readonly) NSString *duration;
 @property (nonatomic, readonly) NSUInteger index;
 
index c8eb3763e498f6a6711fb6b02f1605bc74aa821b..de50bfaf793e43cd7a3be0121cc301f313a18de8 100644 (file)
@@ -19,6 +19,8 @@
 #define decodeDouble(x) x = [decoder decodeDoubleForKey:OBJC_STRINGIFY(x)]
 #define decodeObject(x, cl) x = [HBCodingUtilities decodeObjectOfClass:[cl class] forKey:OBJC_STRINGIFY(x) decoder:decoder];
 
+#define decodeCollectionOfObjects(x, cl, objectcl) x = [HBCodingUtilities decodeObjectOfClasses:[NSSet setWithObjects:[cl class], [objectcl class], nil] forKey:OBJC_STRINGIFY(x) decoder:decoder];
+
 #define decodeObjectOrFail(x, class) x = [HBCodingUtilities decodeObjectOfClass:class forKey:OBJC_STRINGIFY(x) decoder:decoder]; if (x == nil) {NSLog(@"Failed to decode: %@", OBJC_STRINGIFY(x)); goto fail;}
 
 NS_ASSUME_NONNULL_BEGIN
@@ -41,6 +43,9 @@ NS_ASSUME_NONNULL_BEGIN
  */
 + (nullable id)decodeObjectOfClass:(Class)aClass forKey:(NSString *)key decoder:(NSCoder *)decoder;
 
+
++ (nullable id)decodeObjectOfClasses:(NSSet *)classes forKey:(NSString *)key decoder:(NSCoder *)decoder;
+
 @end
 
 NS_ASSUME_NONNULL_END
index a87ad3f7abedbd4f55721436034eb92178487d64..80e245a7b614901495b33f85fdb3f39d0410f33b 100644 (file)
@@ -42,4 +42,17 @@ static BOOL useSecureCoding;
     }
 }
 
++ (id)decodeObjectOfClasses:(NSSet *)classes forKey:(NSString *)key decoder:(NSCoder *)decoder
+{
+    if (useSecureCoding)
+    {
+        return [decoder decodeObjectOfClasses:classes forKey:key];
+    }
+    else
+    {
+        id obj = [decoder decodeObjectForKey:key];
+        return obj;
+    }
+}
+
 @end
index dee8bfc12729746bf1975f6e0bcac02b248d7014..b410da47251062b911b7d8f9f135178ba2c94176 100644 (file)
@@ -35,7 +35,7 @@ typedef NS_ENUM(NSUInteger, HBDistributedArrayContent) {
  */
 @interface HBDistributedArray<ObjectType> : NSMutableArray
 
-- (instancetype)initWithURL:(NSURL *)fileURL;
+- (instancetype)initWithURL:(NSURL *)fileURL class:(Class)objectClass;
 
 /**
  *  Begins a transaction on the array
index d5cb389763f124d898698439e5b9456f53ce3ae3..432e5cd29a6884b26e61c2f93948081808704499 100644 (file)
@@ -59,6 +59,8 @@ NSString *HBDistributedArraWrittenToDisk = @"HBDistributedArraWrittenToDisk";
 @property (nonatomic, readonly) NSURL *fileURL;
 @property (nonatomic, readwrite) NSTimeInterval modifiedTime;
 
+@property (nonatomic, readonly) NSSet *objectClasses;
+
 @property (nonatomic, readonly) sem_t *mutex;
 @property (nonatomic, readwrite) uint32_t mutexCount;
 
@@ -66,13 +68,14 @@ NSString *HBDistributedArraWrittenToDisk = @"HBDistributedArraWrittenToDisk";
 
 @implementation HBDistributedArray
 
-- (instancetype)initWithURL:(NSURL *)fileURL
+- (instancetype)initWithURL:(NSURL *)fileURL class:(Class)objectClass
 {
     self = [super init];
     if (self)
     {
         _fileURL = [fileURL copy];
         _array = [[NSMutableArray alloc] init];
+        _objectClasses = [NSSet setWithObjects:[NSMutableArray class], objectClass, nil];
 
         NSArray *runningInstances = [NSRunningApplication runningApplicationsWithBundleIdentifier:[[NSBundle mainBundle] bundleIdentifier]];
         const char *name = [NSString stringWithFormat:@"/%@.hblock", _fileURL.lastPathComponent].UTF8String;
@@ -196,7 +199,14 @@ NSString *HBDistributedArraWrittenToDisk = @"HBDistributedArraWrittenToDisk";
     NSMutableArray *jobsArray = nil;
     @try
     {
-        jobsArray = [NSKeyedUnarchiver unarchiveObjectWithFile:self.fileURL.path];
+        NSData *queue = [NSData dataWithContentsOfURL:self.fileURL];
+        NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:queue];
+        if ([unarchiver respondsToSelector:@selector(requiresSecureCoding)])
+        {
+            unarchiver.requiresSecureCoding = YES;
+        }
+        jobsArray = [unarchiver decodeObjectOfClasses:self.objectClasses forKey:NSKeyedArchiveRootObjectKey];
+        [unarchiver finishDecoding];
     }
     @catch (NSException *exception)
     {
index e3d608a9ac5e8b006c2c704694aead261e4c01f9..2adee6bbbc799755dbacefec9eaed9ed38f9aa90 100644 (file)
@@ -242,7 +242,7 @@ NSString *HBChaptersChangedNotification  = @"HBChaptersChangedNotification";
 
 - (void)encodeWithCoder:(NSCoder *)coder
 {
-    [coder encodeInt:1 forKey:@"HBJobVersion"];
+    [coder encodeInt:2 forKey:@"HBJobVersion"];
 
     encodeInt(_state);
     encodeObject(_name);
@@ -274,7 +274,7 @@ NSString *HBChaptersChangedNotification  = @"HBChaptersChangedNotification";
 {
     int version = [decoder decodeIntForKey:@"HBJobVersion"];
 
-    if (version == 1 && (self = [super init]))
+    if (version == 2 && (self = [super init]))
     {
         decodeInt(_state);
         decodeObject(_name, NSString);
@@ -304,7 +304,7 @@ NSString *HBChaptersChangedNotification  = @"HBChaptersChangedNotification";
         _video.job = self;
 
         decodeBool(_chaptersEnabled);
-        decodeObject(_chapterTitles, NSArray);
+        decodeCollectionOfObjects(_chapterTitles, NSArray, HBChapter);
 
         return self;
     }
index 1a11d206398574cc5a47d8bb13bd31481782738e..b127347e8849c450e4f552b503f26af65baf1941 100644 (file)
@@ -8,6 +8,8 @@
 #import <Cocoa/Cocoa.h>
 #import "HBHUD.h"
 
+NS_ASSUME_NONNULL_BEGIN
+
 @protocol HBPictureHUDControllerDelegate <NSObject>
 
 - (void)displayPreviewAtIndex:(NSUInteger)idx;
 
 @property (nonatomic, nullable, assign) id<HBPictureHUDControllerDelegate> delegate;
 
-@property (nonatomic, nonnull) NSString *info;
-@property (nonatomic, nonnull) NSString *scale;
+@property (nonatomic, copy) NSString *info;
+@property (nonatomic, copy) NSString *scale;
 
 @property (nonatomic) NSUInteger pictureCount;
 @property (nonatomic) NSUInteger selectedIndex;
 
 @end
+
+NS_ASSUME_NONNULL_END
index 31823371430910fdd86d03e31c445156b928e049..8dfef4e2634a328ce86887a5294f2d1b2b72abfd 100644 (file)
@@ -72,7 +72,7 @@
         _core = [[HBCore alloc] initWithLogLevel:loggingLevel name:@"QueueCore"];
 
         // Load the queue from disk.
-        _jobs = [[HBDistributedArray alloc] initWithURL:queueURL];
+        _jobs = [[HBDistributedArray alloc] initWithURL:queueURL class:[HBJob class]];
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadQueue) name:HBDistributedArrayChanged object:_jobs];
     }
 
index 549d06647aa6e65a4a32c054497064ec5d5a15ff..f1a31174b09423959b4bf7dad9fd02300034fee1 100644 (file)
@@ -83,7 +83,7 @@ extern NSString *keySubTrackSrtFileURL;
         NSDictionary *none = @{  keySubTrackName: NSLocalizedString(@"None", nil)};
         [sourceTracks insertObject:none atIndex:0];
 
-        NSDictionary *foreign = @{ keySubTrackName: foreignAudioSearchTrackName,
+        NSDictionary *foreign = @{ keySubTrackName: [foreignAudioSearchTrackName copy],
                                    keySubTrackType: @(foreignAudioType) };
         [sourceTracks insertObject:foreign atIndex:1];
 
@@ -446,8 +446,8 @@ extern NSString *keySubTrackSrtFileURL;
     self = [super init];
 
     decodeInt(_container);
-    decodeObject(_sourceTracks, NSMutableArray);
-    decodeObject(_tracks, NSMutableArray);
+    decodeCollectionOfObjects(_sourceTracks, NSArray, NSDictionary);
+    decodeCollectionOfObjects(_tracks, NSMutableArray, HBSubtitlesTrack);
 
     for (HBSubtitlesTrack *track in _tracks)
     {
index 66d76efd35c8ec95c96452a0bb3c5ccd6842e528..cfe511157167abd1667441b9311cd7c6bc455540 100644 (file)
@@ -29,7 +29,7 @@ extern NSString *keySubTrackType;
 
 @property (nonatomic, readonly) hb_title_t *hb_title;
 @property (nonatomic, readonly) hb_handle_t *hb_handle;
-@property (nonatomic, readwrite, strong) NSString *name;
+@property (nonatomic, readwrite, copy) NSString *name;
 
 @property (nonatomic, readwrite) NSArray *audioTracks;
 @property (nonatomic, readwrite) NSArray *subtitlesTracks;
index 6dfc16325e2718d8beaed7cc5c02df8268d9c75d..26a45c239c4842bddd821b9463edabef2bf9a3d5 100644 (file)
@@ -552,7 +552,7 @@ NSString * const HBVideoChangedNotification = @"HBVideoChangedNotification";
         [string appendString:@"fastdecode"];
     }
 
-    return string;
+    return [string copy];
 }
 
 - (void)applyPreset:(HBPreset *)preset jobSettings:(NSDictionary *)settings