{"record":{"id":"f455595de182c0fe","repo":"AUTOMATIC1111/stable-diffusion-webui","slug":"data-pkl-not-found-in-filename","errorCode":null,"errorMessage":"data.pkl not found in {filename}","messagePattern":"data\\.pkl not found in (.+?)","errorType":"validation","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"modules/safe.py","lineNumber":89,"sourceCode":"def check_zip_filenames(filename, names):\r\n    for name in names:\r\n        if allowed_zip_names_re.match(name):\r\n            continue\r\n\r\n        raise Exception(f\"bad file inside {filename}: {name}\")\r\n\r\n\r\ndef check_pt(filename, extra_handler):\r\n    try:\r\n\r\n        # new pytorch format is a zip file\r\n        with zipfile.ZipFile(filename) as z:\r\n            check_zip_filenames(filename, z.namelist())\r\n\r\n            # find filename of data.pkl in zip file: '<directory name>/data.pkl'\r\n            data_pkl_filenames = [f for f in z.namelist() if data_pkl_re.match(f)]\r\n            if len(data_pkl_filenames) == 0:\r\n                raise Exception(f\"data.pkl not found in {filename}\")\r\n            if len(data_pkl_filenames) > 1:\r\n                raise Exception(f\"Multiple data.pkl found in {filename}\")\r\n            with z.open(data_pkl_filenames[0]) as file:\r\n                unpickler = RestrictedUnpickler(file)\r\n                unpickler.extra_handler = extra_handler\r\n                unpickler.load()\r\n\r\n    except zipfile.BadZipfile:\r\n\r\n        # if it's not a zip file, it's an old pytorch format, with five objects written to pickle\r\n        with open(filename, \"rb\") as file:\r\n            unpickler = RestrictedUnpickler(file)\r\n            unpickler.extra_handler = extra_handler\r\n            for _ in range(5):\r\n                unpickler.load()\r\n\r\n\r\ndef load(filename, *args, **kwargs):\r","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/82a973c04367123ae98bd9abdf80d9eda9b910e2/modules/safe.py#L71-L107","documentation":"After passing the zip-filename check, check_pt looks for exactly one member matching '<dir>/data.pkl' — the pickle that describes the stored tensors. Zero matches means the archive is a valid zip but has no PyTorch data.pkl, so it cannot be a new-format torch checkpoint, and the Exception is raised (the subsequent BadZipfile branch for legacy format is not taken because the file opened as a zip fine).","triggerScenarios":"Passing a file to torch.load/webui loading that is a valid zip archive but not a torch checkpoint — e.g. a renamed .zip, a .npz, an ONNX file, or a torch .pt' archive whose data.pkl sits at a nonstandard path already rejected earlier.","commonSituations":"Renaming unrelated archives to .ckpt/.pt; corrupted downloads that are actually HTML/error zips; model files from other frameworks accidentally placed in models/Stable-diffusion.","solutions":["Verify the file is a real PyTorch checkpoint: `python -c \"import zipfile;print(zipfile.ZipFile('model.ckpt').namelist())\"` should show data.pkl and data/* entries.","Re-download the model from its official source — a truncated or proxy-replaced download often yields a small invalid zip.","Remove non-checkpoint archives from the models directories so the scanner doesn't try to load them."],"exampleFix":"# before\nmv photos.zip model.ckpt   # renamed archive -> 'data.pkl not found'\n\n# after: use a genuine torch export\n# torch.save(state_dict, 'model.ckpt')  # archive contains data.pkl + data/0...","handlingStrategy":"validation","validationCode":"import re, zipfile\n\ndef has_data_pkl(path):\n    pat = re.compile(r'^([^/]+)/data\\.pkl$')\n    try:\n        with zipfile.ZipFile(path) as z:\n            return any(pat.match(n) for n in z.namelist())\n    except zipfile.BadZipFile:\n        return False  # legacy (non-zip) torch format is handled separately\n\nassert has_data_pkl('model.ckpt'), 'not a new-format torch checkpoint; check the file type/download'","typeGuard":"def looks_like_torch_zip_checkpoint(path: str) -> bool:\n    import re, zipfile\n    pat = re.compile(r'^([^/]+)/data\\.pkl$')\n    try:\n        with zipfile.ZipFile(path) as z:\n            return any(pat.match(n) for n in z.namelist())\n    except zipfile.BadZipFile:\n        return False","tryCatchPattern":"try:\n    weights = torch.load(path)\nexcept Exception as e:\n    if 'data.pkl not found' in str(e):\n        raise RuntimeError(f'{path} is a zip but not a torch checkpoint; verify the download/source')\n    raise","preventionTips":["Verify downloads by size/checksum against the official release before loading.","Keep models directories free of unrelated zip/npz/renamed files."],"tags":["security","pickle","checkpoint","file-format","corruption"],"backgroundTag":null,"analyzedSha":"82a973c04367123ae98bd9abdf80d9eda9b910e2","analyzedAt":"2026-08-14T16:46:43.225Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}