From 5cf4ba75b3b39dafebcfb5178a97e61d9005b878 Mon Sep 17 00:00:00 2001 From: mac Date: Wed, 4 Nov 2026 22:00:35 +0800 Subject: [PATCH] fix: validate LUT paths and verify independent layer writes after host commit --- 大鱼调色/Plugin/DYColorWorkspace.mm | 14 +++++++-- .../Plugin/DYWorkspaceDiagnosticHost.inc.h | 4 +-- 大鱼调色/Plugin/DYWorkspaceDiagnostics.inc.h | 30 +++++++++++-------- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/大鱼调色/Plugin/DYColorWorkspace.mm b/大鱼调色/Plugin/DYColorWorkspace.mm index 4874494..fe552d5 100644 --- a/大鱼调色/Plugin/DYColorWorkspace.mm +++ b/大鱼调色/Plugin/DYColorWorkspace.mm @@ -196,18 +196,26 @@ } - (BOOL)commitLUT:(NSString *)path error:(NSError **)error{return [self commitLUT:path expected:[self selectionContext] error:error];} - (BOOL)commitLUT:(NSString *)path expected:(NSDictionary *)expected error:(NSError **)error{ + if(path.length&&(!path.isAbsolutePath||![[path.pathExtension lowercaseString]isEqual:@"cube"])){ + if(error)*error=[NSError errorWithDomain:@"com.dayu.color.workspace" code:1 userInfo:@{NSLocalizedDescriptionKey:@"LUT 必须是完整路径的 .cube 文件,原来的选择已保留"}];return NO; + } id action=[self actionAPI];BOOL written=NO;NSString *failure=nil;if(!action)failure=@"宿主暂时无法应用 LUT,请重新选择当前效果后重试"; else{id outer=[_manager isKindOfClass:DYToolManager.class]?[[(DYToolManager*)_manager host]apiForProtocol:@protocol(FxCustomParameterActionAPI_v4)]:nil; - if(outer)[outer startAction:self];[action startAction:self];id undo=nil;BOOL grouped=NO;@try{ + if(outer)[outer startAction:self];[action startAction:self];id undo=nil;BOOL grouped=NO;NSDictionary *wantedPaths=nil;CMTime commitTime=kCMTimeInvalid;@try{ CMTime time=action.currentTime,original=kCMTimeInvalid;NSData *encodedTime=expected[@"time"];if(encodedTime.length==sizeof(original))memcpy(&original,encodedTime.bytes,sizeof(original)); if(!CMTIME_IS_NUMERIC(time)||!CMTIME_IS_NUMERIC(original)||CMTimeCompare(time,original)!=0)failure=@"播放头已改变,未将先前的 LUT 选择写到新画面;请重新选择"; else if(![[self selectionContextAtTime:time][@"state"]isEqual:expected[@"state"]])failure=@"载入期间风格1或色彩管理已改变,已保留最新设置;请重新选择 LUT"; if(!failure&&[_manager isKindOfClass:DYToolManager.class]){DYToolManager *node=(DYToolManager*)_manager;if(![node.type isEqual:@"look"]||!DYToolWithID(DYReadTools(node.host,time).document,node.nodeID)){failure=@"此风格图层已删除或不再可编辑,未修改其它图层";}} if(!failure&&![_manager isKindOfClass:DYToolManager.class]&&DYBaseToolRemoved(DYReadTools(_manager,time).document,@"look"))failure=@"基础风格工具已移除,请先恢复风格工具;未修改其它图层"; if(!failure){DYAssetState *assets=[[DYReadAssets(_manager,time)copy]autorelease];if(!assets)assets=[[[DYAssetState alloc]init]autorelease];NSMutableDictionary *paths=[[assets.paths mutableCopy]autorelease]?:[NSMutableDictionary dictionary];if(path.length)paths[@"look0"]=path;else[paths removeObjectForKey:@"look0"];assets.paths=paths; - undo=[_manager apiForProtocol:@protocol(FxUndoAPI)];grouped=[undo startUndoGroup:@"选择风格1 LUT"];written=DYWriteAssets(_manager,assets,time);if(!written)failure=@"宿主未接受此 LUT,原来的选择已保留"; + wantedPaths=assets.paths;commitTime=time;undo=[_manager apiForProtocol:@protocol(FxUndoAPI)];grouped=[undo startUndoGroup:@"选择风格1 LUT"];written=DYWriteAssets(_manager,assets,time);if(!written)failure=@"宿主未接受此 LUT,原来的选择已保留"; } - }@finally{if(outer){[action endAction:self];if(grouped)[undo endUndoGroup];[outer endAction:self];}else{if(grouped)[undo endUndoGroup];[action endAction:self];}}} + }@finally{if(outer){[action endAction:self]; + // DYToolManager stages custom assets and commits its host document in + // endAction. Its earlier setter BOOL does not report that final write. + // Read the actual target while the outer host action still grants access. + if(written){DYToolManager *node=(DYToolManager*)_manager;NSDictionary *stored=DYToolWithID(DYReadTools(node.host,commitTime).document,node.nodeID);if(!stored||![stored[@"paths"]isEqual:wantedPaths]){written=NO;failure=@"宿主未保存此风格图层的 LUT,原来的选择已保留;请重试";}} + if(grouped)[undo endUndoGroup];[outer endAction:self];}else{if(grouped)[undo endUndoGroup];[action endAction:self];}}} if(written){if(path.length)[_library recordUsedPath:path];[NSNotificationCenter.defaultCenter postNotificationName:DYModelChanged object:[_manager isKindOfClass:DYToolManager.class]?[(DYToolManager*)_manager host]:_manager];} else if(error)*error=[NSError errorWithDomain:@"com.dayu.color.workspace" code:1 userInfo:@{NSLocalizedDescriptionKey:failure?:@"LUT 操作未完成"}];return written; } diff --git a/大鱼调色/Plugin/DYWorkspaceDiagnosticHost.inc.h b/大鱼调色/Plugin/DYWorkspaceDiagnosticHost.inc.h index dec4bb3..f00f348 100644 --- a/大鱼调色/Plugin/DYWorkspaceDiagnosticHost.inc.h +++ b/大鱼调色/Plugin/DYWorkspaceDiagnosticHost.inc.h @@ -6,7 +6,7 @@ - (NSProgress *)selectLUT:(NSString *)path completion:(void(^)(NSError *))completion; @end @interface DYWorkspaceDiagnosticHost : DYDiagnosticManager { -@public NSView *_parent;CMTime _workspaceTime;NSUInteger _requests,_closes;NSInteger _actionDepth;BOOL _permissionFailure,_nodeCommitHadUndo; +@public NSView *_parent;CMTime _workspaceTime;NSUInteger _requests,_closes;NSInteger _actionDepth;BOOL _permissionFailure,_nodeCommitHadUndo,_rejectToolsWrites; } @end @implementation DYWorkspaceDiagnosticHost @@ -17,7 +17,7 @@ - (CMTime)currentTime{return _workspaceTime;} - (void)remoteWindowWithMinimumSize:(CGSize)minimum maximumSize:(CGSize)maximum reply:(void(^)(FxXPView*,NSError*))reply{if(!_actionDepth)_permissionFailure=YES;_requests++;reply((FxXPView*)_parent,nil);} - (void)closeRemoteWindow{if(!_actionDepth)_permissionFailure=YES;_closes++;} -- (BOOL)setCustomParameterValue:(NSObject *)value toParameter:(UInt32)pid atTime:(CMTime)time{if(pid==DYToolsParameterID)_nodeCommitHadUndo=_undoActive;return [super setCustomParameterValue:value toParameter:pid atTime:time];} +- (BOOL)setCustomParameterValue:(NSObject *)value toParameter:(UInt32)pid atTime:(CMTime)time{if(pid==DYToolsParameterID){_nodeCommitHadUndo=_undoActive;if(_rejectToolsWrites)return NO;}return [super setCustomParameterValue:value toParameter:pid atTime:time];} @end @interface DYWorkspaceDiagnosticRenderer : DYRenderer{ @public NSProgress *_preparedTask;void(^_preparedReply)(NSError*); diff --git a/大鱼调色/Plugin/DYWorkspaceDiagnostics.inc.h b/大鱼调色/Plugin/DYWorkspaceDiagnostics.inc.h index ffc7074..3e6953f 100644 --- a/大鱼调色/Plugin/DYWorkspaceDiagnostics.inc.h +++ b/大鱼调色/Plugin/DYWorkspaceDiagnostics.inc.h @@ -1,5 +1,6 @@ { auto workspaceDrain=[](){double end=NSProcessInfo.processInfo.systemUptime+.04;while(NSProcessInfo.processInfo.systemUptime_undoStarts,ends=host->_undoEnds;NSError *workspaceError=nil; - BOOL wrote=[workspace commitLUT:@"new.cube" expected:[workspace selectionContext] error:&workspaceError]; - run.record(@"workspace-style1-preserves-other-lut-slots-one-undo",wrote&&[DYReadAssets(host,kCMTimeZero).paths[@"look0"]isEqual:@"new.cube"]&&[DYReadAssets(host,kCMTimeZero).paths[@"look1"]isEqual:@"retain.cube"]&&host->_undoStarts==starts+1&&host->_undoEnds==ends+1); + BOOL wrote=[workspace commitLUT:newLUT expected:[workspace selectionContext] error:&workspaceError]; + run.record(@"workspace-style1-preserves-other-lut-slots-one-undo",wrote&&[DYReadAssets(host,kCMTimeZero).paths[@"look0"]isEqual:newLUT]&&[DYReadAssets(host,kCMTimeZero).paths[@"look1"]isEqual:retainLUT]&&host->_undoStarts==starts+1&&host->_undoEnds==ends+1); __block BOOL completed=NO;__block NSError *selectionError=nil;starts=host->_undoStarts; [workspace selectLUT:nil completion:^(NSError *e){completed=YES;selectionError=e;}];workspaceDrain(); run.record(@"workspace-remove-style1-applies-once-after-async-boundary",completed&&!selectionError&&!DYReadAssets(host,kCMTimeZero).paths[@"look0"]&&host->_undoStarts==starts+1); - completed=NO;selectionError=nil;[workspace selectLUT:@"late.cube" completion:^(NSError *e){completed=YES;selectionError=e;}];host->_workspaceTime=CMTimeMake(1,24);[scopeRenderer completePreparation]; + completed=NO;selectionError=nil;[workspace selectLUT:lateLUT completion:^(NSError *e){completed=YES;selectionError=e;}];host->_workspaceTime=CMTimeMake(1,24);[scopeRenderer completePreparation]; run.record(@"workspace-async-playhead-change-keeps-new-frame-untouched",completed&&selectionError&&!DYReadAssets(host,kCMTimeZero).paths[@"look0"]);host->_workspaceTime=kCMTimeZero; - completed=NO;selectionError=nil;[workspace selectLUT:@"late.cube" completion:^(NSError *e){completed=YES;selectionError=e;}];DYAssetState *external=[[DYReadAssets(host,kCMTimeZero)copy]autorelease];external.paths=@{@"look0":@"user-new.cube"};DYWriteAssets(host,external,kCMTimeZero);[scopeRenderer completePreparation]; - run.record(@"workspace-async-lut-conflict-preserves-user-change",completed&&selectionError&&[DYReadAssets(host,kCMTimeZero).paths[@"look0"]isEqual:@"user-new.cube"]); - completed=NO;selectionError=nil;[workspace selectLUT:@"late.cube" completion:^(NSError *e){completed=YES;selectionError=e;}];for(NSDictionary *d in DYDescriptors())if([d[@"key"]isEqual:@"cmworkingTransfer"])[host setFloatValue:3 toParameter:[d[@"pid"]unsignedIntValue] atTime:kCMTimeZero];[scopeRenderer completePreparation]; - run.record(@"workspace-async-color-context-conflict-preserves-state",completed&&selectionError&&[DYReadAssets(host,kCMTimeZero).paths[@"look0"]isEqual:@"user-new.cube"]); - completed=NO;selectionError=nil;NSProgress *pending=[workspace selectLUT:@"late.cube" completion:^(NSError *e){completed=YES;selectionError=e;}];[workspace close];[scopeRenderer completePreparation]; - run.record(@"workspace-close-cancels-pending-selection-without-write",pending.cancelled&&completed&&selectionError&&[DYReadAssets(host,kCMTimeZero).paths[@"look0"]isEqual:@"user-new.cube"]); + completed=NO;selectionError=nil;[workspace selectLUT:lateLUT completion:^(NSError *e){completed=YES;selectionError=e;}];DYAssetState *external=[[DYReadAssets(host,kCMTimeZero)copy]autorelease];external.paths=@{@"look0":userLUT};DYWriteAssets(host,external,kCMTimeZero);[scopeRenderer completePreparation]; + run.record(@"workspace-async-lut-conflict-preserves-user-change",completed&&selectionError&&[DYReadAssets(host,kCMTimeZero).paths[@"look0"]isEqual:userLUT]); + completed=NO;selectionError=nil;[workspace selectLUT:lateLUT completion:^(NSError *e){completed=YES;selectionError=e;}];for(NSDictionary *d in DYDescriptors())if([d[@"key"]isEqual:@"cmworkingTransfer"])[host setFloatValue:3 toParameter:[d[@"pid"]unsignedIntValue] atTime:kCMTimeZero];[scopeRenderer completePreparation]; + run.record(@"workspace-async-color-context-conflict-preserves-state",completed&&selectionError&&[DYReadAssets(host,kCMTimeZero).paths[@"look0"]isEqual:userLUT]); + completed=NO;selectionError=nil;NSProgress *pending=[workspace selectLUT:lateLUT completion:^(NSError *e){completed=YES;selectionError=e;}];[workspace close];[scopeRenderer completePreparation]; + run.record(@"workspace-close-cancels-pending-selection-without-write",pending.cancelled&&completed&&selectionError&&[DYReadAssets(host,kCMTimeZero).paths[@"look0"]isEqual:userLUT]); NSMutableDictionary *document=DYMutablePlist(DYReadTools(host,kCMTimeZero).document);NSDictionary *look=DYInsertTool(document,@"look",@"base:look");NSString *nodeID=[[look[@"id"]copy]autorelease];BOOL inserted=look&&DYWriteTools(host,document,kCMTimeZero);run.need(@"workspace-independent-style-fixture-inserted",inserted,@{@"node":nodeID?:@"missing",@"validDocument":@(DYValidToolDocument(document))}); DYToolManager *node=[[[DYToolManager alloc]initWithHost:host node:look]autorelease];DYColorWorkspace *nodeWorkspace=[[[DYColorWorkspace alloc]initWithManager:node renderer:scopeRenderer library:scopeLibrary title:@"独立风格"]autorelease];starts=host->_undoStarts;host->_nodeCommitHadUndo=NO; - wrote=[nodeWorkspace commitLUT:@"node.cube" expected:[nodeWorkspace selectionContext] error:&workspaceError]; - run.record(@"workspace-independent-style1-writes-target-node-inside-undo",wrote&&[DYToolWithID(DYReadTools(host,kCMTimeZero).document,nodeID)[@"paths"][@"look0"]isEqual:@"node.cube"]&&[DYReadAssets(host,kCMTimeZero).paths[@"look0"]isEqual:@"user-new.cube"]&&host->_nodeCommitHadUndo&&host->_undoStarts==starts+1,@{@"written":@(wrote),@"error":workspaceError.localizedDescription?:@"none",@"nodePaths":DYToolWithID(DYReadTools(host,kCMTimeZero).document,nodeID)[@"paths"]?:@{},@"rootStyle1":DYReadAssets(host,kCMTimeZero).paths[@"look0"]?:@"none",@"commitWithinUndo":@(host->_nodeCommitHadUndo),@"undoStartsBefore":@(starts),@"undoStartsAfter":@(host->_undoStarts)}); + wrote=[nodeWorkspace commitLUT:nodeLUT expected:[nodeWorkspace selectionContext] error:&workspaceError]; + run.record(@"workspace-independent-style1-writes-target-node-inside-undo",wrote&&[DYToolWithID(DYReadTools(host,kCMTimeZero).document,nodeID)[@"paths"][@"look0"]isEqual:nodeLUT]&&[DYReadAssets(host,kCMTimeZero).paths[@"look0"]isEqual:userLUT]&&host->_nodeCommitHadUndo&&host->_undoStarts==starts+1,@{@"written":@(wrote),@"error":workspaceError.localizedDescription?:@"none",@"nodePaths":DYToolWithID(DYReadTools(host,kCMTimeZero).document,nodeID)[@"paths"]?:@{},@"rootStyle1":DYReadAssets(host,kCMTimeZero).paths[@"look0"]?:@"none",@"commitWithinUndo":@(host->_nodeCommitHadUndo),@"undoStartsBefore":@(starts),@"undoStartsAfter":@(host->_undoStarts)}); + starts=host->_undoStarts;workspaceError=nil;wrote=[nodeWorkspace commitLUT:@"relative.cube" expected:[nodeWorkspace selectionContext] error:&workspaceError];run.record(@"workspace-relative-lut-path-is-rejected-before-undo",!wrote&&workspaceError&&host->_undoStarts==starts&&[DYToolWithID(DYReadTools(host,kCMTimeZero).document,nodeID)[@"paths"][@"look0"]isEqual:nodeLUT]); + host->_rejectToolsWrites=YES;workspaceError=nil;wrote=[nodeWorkspace commitLUT:newLUT expected:[nodeWorkspace selectionContext] error:&workspaceError];host->_rejectToolsWrites=NO; + run.record(@"workspace-node-host-rejection-is-not-reported-as-applied",!wrote&&workspaceError&&[DYToolWithID(DYReadTools(host,kCMTimeZero).document,nodeID)[@"paths"][@"look0"]isEqual:nodeLUT],@{@"error":workspaceError.localizedDescription?:@"missing"}); document=DYMutablePlist(DYReadTools(host,kCMTimeZero).document);DYRemoveTool(document,nodeID);DYWriteTools(host,document,kCMTimeZero);starts=host->_undoStarts;workspaceError=nil; - wrote=[nodeWorkspace commitLUT:@"deleted.cube" expected:[nodeWorkspace selectionContext] error:&workspaceError];run.record(@"workspace-deleted-node-does-not-write-another-layer",!wrote&&workspaceError&&host->_undoStarts==starts&&[DYReadAssets(host,kCMTimeZero).paths[@"look0"]isEqual:@"user-new.cube"]); + wrote=[nodeWorkspace commitLUT:deletedLUT expected:[nodeWorkspace selectionContext] error:&workspaceError];run.record(@"workspace-deleted-node-does-not-write-another-layer",!wrote&&workspaceError&&host->_undoStarts==starts&&[DYReadAssets(host,kCMTimeZero).paths[@"look0"]isEqual:userLUT]); [nodeWorkspace close];run.record(@"workspace-offscreen-fixtures-never-presented",!fixture.visible&&!host->_permissionFailure&&host->_actionDepth==0); // Run the production final-tile sampling and worker color conversion on a // known premultiplied half-float host output, independently of LUT analysis.