modelscan-cloudpickle-dill-false-negative-poc / verify_cloudpickle_dill_load.py
AM-Core's picture
Upload folder using huggingface_hub
9c37cfa verified
from pathlib import Path
import cloudpickle
import dill
ROOT = Path(__file__).resolve().parent
LOGS = ROOT / "logs"
LOGS.mkdir(parents=True, exist_ok=True)
marker = LOGS / "serialization_canary_loaded.txt"
cases = [
("cloudpickle", cloudpickle.load, ROOT / "canary_cloudpickle.pkl"),
("dill", dill.load, ROOT / "canary_dill.pkl"),
]
for name, loader, path in cases:
marker.unlink(missing_ok=True)
print(f"===== CONTROLLED LOAD: {name} =====")
print(f"file={path}")
print(f"exists_before={marker.exists()}")
with path.open("rb") as f:
loader(f)
print(f"exists_after={marker.exists()}")
if marker.exists():
print(f"marker_content={marker.read_text().strip()}")
print()