mirror of
https://github.com/huggingface/transformers.git
synced 2025-10-20 17:13:56 +08:00
path validation for security reason (#41256)
fix Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
This commit is contained in:
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import transformers
|
import transformers
|
||||||
|
|
||||||
@ -69,6 +70,15 @@ def convert_slow_checkpoint_to_fast(tokenizer_name, checkpoint_name, dump_path,
|
|||||||
if "/" in checkpoint:
|
if "/" in checkpoint:
|
||||||
checkpoint_directory, checkpoint_prefix_name = checkpoint.split("/")
|
checkpoint_directory, checkpoint_prefix_name = checkpoint.split("/")
|
||||||
dump_path_full = os.path.join(dump_path, checkpoint_directory)
|
dump_path_full = os.path.join(dump_path, checkpoint_directory)
|
||||||
|
|
||||||
|
# Security check
|
||||||
|
try:
|
||||||
|
Path(dump_path_full).resolve().relative_to(Path(dump_path).resolve())
|
||||||
|
except ValueError:
|
||||||
|
raise ValueError(
|
||||||
|
f"Invalid checkpoint path: '{checkpoint}' attempts to escape `dump_path`: {dump_path}"
|
||||||
|
)
|
||||||
|
|
||||||
elif add_prefix:
|
elif add_prefix:
|
||||||
checkpoint_prefix_name = checkpoint
|
checkpoint_prefix_name = checkpoint
|
||||||
dump_path_full = dump_path
|
dump_path_full = dump_path
|
||||||
|
Reference in New Issue
Block a user