arXiv:2610.10735cs.CROct 2026

Manuscript Offprint

arXiv:2610.10735

DITTO: A Context-aware Pickle-based Pre-Trained Model Scanner for Effective Security Audits

Qiaolin Qin, Wanpeng Li, Benoit Baudry, Lorenzo De Carli, Heng Li, Ettore Merlo

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Qiaolin Qin*, Wanpeng Li†, Benoit Baudry‡, Lorenzo De Carli§, Heng Li*, Ettore Merlo*

*Polytechnique Montreal, Montreal, Canada, † University of Liverpool, Liverpool, England

†Université de Montréal, Montreal, Canada, § University of Calgary, Calgary, Canada

{qiaolin.qin, heng.li, ettore.merlo}@polymtl.ca, wanpeng.li@liverpool.ac.uk, benoit.baudry@umontreal.ca, lorenzo.decarli@ucalgary.ca

Abstract—Pre-trained models (PTMs) are widely distributed as serialized binaries, but their reuse often exposes software supply chains to deserialization attacks. Despite the emergence of safer serialization formats, the unsafe Pickle format remains prevalent: our analysis of over 10,000 popular Hugging Face repositories reveals that 9.3% rely on Pickle. While many defense mechanisms have been proposed, state-of-the-art model scanners suffer from a coverage-precision gap, missing security-sensitive behaviors and generating excessive false alerts. In this paper, we introduce DITTO, the first stack-based, context-aware scanner for Pickle-based PTMs. DITTO faithfully tracks Pickle virtual machine state transitions and performs context-aware semantic analysis to infer model intentions. We also present PickleBench, a benchmark of 959 benign and 92 malicious real-world models, including extension registry attacks previously missed by existing tools. Across multiple evaluations, DITTO achieves 100% scanning coverage, a 0% false-negative rate, and a 0.7% false-positive rate, yielding an F1 score of 0.966, significantly outperforming state-of-the-art scanners. By minimizing false alerts while preserving detection accuracy, DITTO generates actionable security reports with contextual evidence, enabling safe PTM reuse and strengthening software supply chain integrity.

Index Terms—Systems and Software, Invasive software (viruses, worms, Trojan horses), Security, Software maintenance

I. INTRODUCTION

As AI technology advances, open-source pre-trained models (PTMs) are increasingly integrated into software supply chains [1]–[3]. Such models are pre-trained on large datasets and can be directly reused or fine-tuned for tasks across various domains [4]–[8]. Popular public model hubs such as Hugging Face host millions of PTMs [6]. To facilitate model sharing and reuse, PTMs are distributed as serialized binary files that are deserialized to reconstruct model objects on users' systems [9]. While reusing open-source PTMs reduces development cost, deserializing untrusted models introduces a critical software supply chain risk: a malicious serialized model can trigger attacker-controlled behavior during loading, leading to arbitrary code execution, data exfiltration, or file manipulation [10]–[14].

Safer serialization formats such as Safetensors [15] and GGUF [16] have emerged to mitigate these risks. Nevertheless, Pickle [17], an expressive but inherently unsafe serialization format, remains prevalent in public PTMs. According to our investigation of 10,023 popular Hugging Face repositories created over the past year, we identified 9,544 Pickle-based PTMs across 929 repositories (9.3%). These models include highly downloaded PTMs and models published by major organizations such as NVIDIA, IBM, and OpenAI. Thus, protecting users from malicious Pickle-based PTMs remains a practical problem.

Pickle is unsafe because it can trigger attacker-controlled behavior with three types of security-sensitive deserialization operations: import, invoke, and alter. We demonstrate common attack patterns in section II-B. Existing defenses primarily rely on restricted loaders and model scanners. Restricted loaders [11], [18] only execute predefined safe operations during deserialization, but frequently prevent benign models from loading. Model scanners [19]–[21] instead analyze PTMs before loading and report potentially risky behavior for security audits. This flexibility makes scanners attractive for safe model reuse, and Hugging Face itself uses PickleScan [22] to scan Pickle-based models. However, our analysis reveals a coverage-precision gap in existing scanners: they can fail to capture security-sensitive deserialization behavior, while conservatively flagging risky or unknown operations can lead to substantial false positives. In our study, PickleScan falsely flags 177 of 706 benign models (25.1%), illustrating the auditing burden introduced by false alerts. In addition, their scanning reports are either incomplete or redundant, which hinders downstream security audits. Based on our investigation, we summarize three key challenges in designing a reliable model scanner:

C1: How can a scanner faithfully capture security-sensitive deserialization behavior? (section III-B2) Prior work shows that mismatches between scanner and framework loading paths allow malicious Pickle streams to evade analysis [23]. Additionally, we uncover a previously unexamined blind spot in Pickle's extension registry mechanism, which cannot be faithfully tracked by existing scanners.

C2: How can a scanner distinguish malicious behavior from legitimate model reconstruction? (section III-B3) Existing scanners share a syntax-oriented strategy. They primarily infer risk from the identities of imported globals (i.e., importable classes, functions, and objects). However, since the same global can participate in either legitimate model reconstruction or malicious behavior, its security implication cannot be determined solely by its identity.

C3: How can context-aware analysis remain practical and reliable? (section III-B4) Context information such as deserialization states is crucial for reasoning about model intention. Yet, overly detailed information, such as a complete deserialization trace, can contain much routine information unrelated to security-sensitive operations and distract analysis.

To address these challenges, we propose DITTO (Deserialization Inspector for Threatening Trojanized Objects), the first stack-based, context-aware scanner for Pickle-based PTMs. DITTO comprises two major components: a trace generator and an intention analyzer. To address C1, the trace generator implements framework-consistent model loading and emulates the stack-based Pickle virtual machine (PVM) to generate a deserialization trace without dynamically executing security-sensitive operations. To address C2, the intention analyzer extracts security-critical states from the trace and performs automated semantic analysis over their usage context to reason about their legitimacy. The extracted security-critical states and the final reasoning reports are auditable assessment evidence that co-addresses C3. This design enables DITTO to safely track and reason about deserialization behaviors and support downstream audits.

To systematically evaluate and compare DITTO with state-of-the-art scanners, we construct PickleBench. The benchmark comprises 959 benign real-world Pickle-based PTMs and 92 representative malicious models, including previously studied attacks [11], [13], [14], [23] and our uncovered extension registry attacks. Under its default configuration, DITTO successfully scans all models and detects all malicious instances, maintaining a 100% scanning coverage and a 0% false-negative rate across three independent runs. At the same time, it produces only 0.7% false positives on average, resulting in an F1 score of 0.966, substantially higher than the 0.776 F1 score achieved by the best-performing existing scanner on the same benchmark. Our ablation study shows that DITTO's security-critical state extraction promotes its scanning performance by removing redundant reconstruction states. We also demonstrate how different semantic analyzers impact DITTO's context-aware classification performance. By substantially reducing false alerts while preserving detection coverage, DITTO enables more actionable human-in-the-loop security auditing of untrusted PTMs. In summary, our study makes the following contributions:

  1. Large-scale study of recent Pickle usage. We conduct a large-scale investigation of Pickle usage in 10,023 popular Hugging Face repositories created between July 1, 2025 and June 30, 2026. We identify 9,544 Pickle-based PTMs across 929 repositories (9.3%), demonstrating that Pickle remains prevalent in recently published and widely reused PTMs.

  2. Discovery of Extension Registry Exploitation. Our analysis of model scanners uncovers a previously unexamined blind spot in Pickle's EXT operations, where registry manipulation can redirect extension opcodes to risky globals without being tracked by scanners.

  3. PickleBench construction. We construct PickleBench, a benchmark of 959 benign and 92 malicious models that combines rigorously validated real-world PTMs with representative deserialization attacks.

  4. Stack-based, context-aware PTM scanning. We present DITTO, the first stack-based, context-aware scanner for Pickle-based PTMs. DITTO faithfully captures security-sensitive PVM operations and conducts automated semantic analysis. DITTO consistently achieved a 100% scanning coverage, 0% FNR, and a 0.7% FPR on PickleBench. It reduces the manual effort imposed by false security alerts and provides practical reports that facilitate security audits for PTM reuse.

References (43)