Implementation:Trailofbits Fickling Create Polyglot
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Security_Research, Supply_Chain, File_Format |
| Last Updated | 2026-02-14 14:00 GMT |
Overview
Concrete tool for creating PyTorch polyglot files from two different format files, provided by the Fickling library.
Description
create_polyglot takes two PyTorch files of different formats, identifies their formats, and combines them into a single polyglot file. It delegates to format-specific creators: create_mar_legacy_pickle_polyglot, create_standard_torchscript_polyglot, or create_mar_legacy_tar_polyglot depending on the format combination. Returns a boolean indicating success.
Usage
Use for security research: creating test polyglots to validate detection capabilities.
Code Reference
Source Location
- Repository: fickling
- File: fickling/polyglot.py
- Lines: L402-437
Signature
def create_polyglot(
first_file: str,
second_file: str,
polyglot_file_name: str | None = None,
print_results: bool = True
) -> bool:
"""Create a polyglot from two PyTorch files of different formats.
Args:
first_file: Path to the first PyTorch file.
second_file: Path to the second PyTorch file.
polyglot_file_name: Output filename (auto-determined if None).
print_results: Print progress to stdout.
Returns:
True if a polyglot was successfully created, False otherwise.
Supported combinations:
- MAR + PyTorch v0.1.10
- PyTorch v1.3 + TorchScript v1.4
- MAR + PyTorch v0.1.1
"""
Import
from fickling.polyglot import create_polyglot
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| first_file | str | Yes | Path to the first PyTorch file |
| second_file | str | Yes | Path to the second PyTorch file (different format) |
| polyglot_file_name | str or None | No | Output filename (auto-determined if None) |
| print_results | bool | No | Print progress (default: True) |
Outputs
| Name | Type | Description |
|---|---|---|
| (return) | bool | True if polyglot was created successfully |
| Side effect | File | Polyglot file written to polyglot_file_name |
Usage Examples
Create a PyTorch/TorchScript Polyglot
from fickling.polyglot import create_polyglot, identify_pytorch_file_format
# Create polyglot from two different format files
success = create_polyglot(
first_file="model_v13.pt",
second_file="model_ts14.pt",
polyglot_file_name="polyglot_test.pt"
)
if success:
# Verify polyglot detection
formats = identify_pytorch_file_format("polyglot_test.pt")
print(f"Detected formats: {formats}")
assert len(formats) > 1, "Polyglot should be detected as multiple formats"
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment