Summary
A flaw in picklescan before 0.0.28 fails to detect malicious calls to torch.utils.bottleneck.__main__.run_cprofile embedded inside pickle files.
Remote attackers can craft pickle payloads that bypass picklescan's safety checks and execute arbitrary code when victims load these files, especially in ML and data-processing workflows.
Affected context
This vulnerability affects environments that rely on picklescan as a safety gate before loading Python pickle files, particularly in machine learning, data science, and model-sharing pipelines.
It becomes relevant when pickle files originating from semi-trusted or untrusted sources are scanned with picklescan under the assumption that malicious code will be detected.
The issue is present when torch-based pickle payloads can be imported and executed, and the execution environment treats a "clean" picklescan result as sufficient for safe loading.
Exploit preconditions
- Attack surface: Applications, scripts, or services that accept pickle files and use picklescan for safety checking before loading them.
- Required access: Ability to supply or influence pickle files consumed by a victim (e.g., uploaded models, shared datasets, or serialized objects).
- Trigger point: The victim runs picklescan, receives a non-malicious verdict, and subsequently deserializes the pickle using Python's
pickleor compatible loaders. - Why exploitation is possible: picklescan before 0.0.28 does not recognize malicious
torch.utils.bottleneck.__main__.run_cprofilefunction calls, leaving a critical execution path unflagged and allowing embedded code to run during unpickling.
Why this happens
The underlying issue is incomplete detection logic for unsafe deserialization patterns within pickle payloads.
picklescan's analysis fails to treat specific torch.utils.bottleneck.__main__.run_cprofile call chains as dangerous, leaving a gap in its model of risky object graphs and function invocations.
This maps to CWE-502: Unsafe Deserialization, where untrusted serialized data drives object construction and function execution.
Conceptually, the bug arises from over-reliance on pattern-based filtering without comprehensive coverage of all high-risk execution primitives in the Python and PyTorch ecosystem.
Potential impact
- Attackers may achieve arbitrary code execution when the victim deserializes a "scan-approved" pickle file.
- Malicious payloads could install backdoors or steal credentials from the environment loading the pickle.
- Compromise of ML training or inference infrastructure, including alteration of models and datasets.
- Lateral movement within the host or environment if deserialization occurs in a privileged or networked process.
General mitigation guidance
Mitigation efforts should focus on reducing trust in pickle-based serialization and tightening deserialization boundaries.
Recommended patterns include:
- Treating all pickle files from external or shared sources as untrusted and avoiding automatic loading where possible.
- Using safer, data-only serialization formats (e.g., JSON, Protobuf, or custom schemas) for interchange between systems and users.
- Implementing strict allowlists for modules, classes, and functions that can be deserialized, limiting code-bearing constructs.
- Running any required deserialization in strongly sandboxed, least-privilege environments with constrained filesystem and network access.
- Incorporating layered checks (static inspection, schema validation, and behavioral constraints) rather than depending on a single scanner.
How teams detect issues like this
Detection can focus on both code-level and operational signals:
- Static analysis rules that flag use of generic
pickle.load,torch.load, and similar APIs on untrusted data paths. - Code review checklists that question reliance on third-party scanners as the sole safety mechanism for serialization.
- Policies that prohibit loading pickles from network inputs, shared storage, or user uploads without additional validation or sandboxing.
- Instrumentation and logging around deserialization routines to observe unusual module imports or function calls during unpickling.
- Automated security review tools configured to highlight unsafe deserialization patterns and usage of high-risk modules like
torch.utils.bottleneck.

