| import os | |
| def resolve_output_file_path(output_root, output_file_path, file_name, file_extension): | |
| """Resolve a workflow-provided output path beneath ``output_root``. | |
| Relative output directories remain supported, but are interpreted relative | |
| to ComfyUI's configured output directory rather than the process working | |
| directory. Resolving both paths prevents ``..`` components and existing | |
| symlinks from escaping the allowed root. | |
| """ | |
| output_root = os.path.realpath(output_root) | |
| requested_directory = output_file_path | |
| if not os.path.isabs(requested_directory): | |
| requested_directory = os.path.join(output_root, requested_directory) | |
| candidate = os.path.realpath( | |
| os.path.join(requested_directory, f"{file_name}.{file_extension}") | |
| ) | |
| try: | |
| is_within_output = os.path.commonpath((output_root, candidate)) == output_root | |
| except ValueError: | |
| # Different Windows drives and paths containing null bytes are unsafe. | |
| is_within_output = False | |
| if not is_within_output: | |
| raise ValueError("Saving outside the ComfyUI output directory is not allowed") | |
| return candidate | |
Xet Storage Details
- Size:
- 1.16 kB
- Xet hash:
- ab61bbe9257703579120da6d753790b6760b83c0d6d3456bb8a631bdedf2e752
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.