Implementation:Trailofbits Fickling Find File Properties
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Security, File_Format, Supply_Chain |
| Last Updated | 2026-02-14 14:00 GMT |
Overview
Concrete tool for discovering structural properties of PyTorch files provided by the Fickling library.
Description
find_file_properties opens a file and runs multiple structural checks to produce a boolean properties dictionary. It checks PyTorch ZIP magic numbers, tar headers, pickle validity, NumPy headers, and ZIP archive contents (data.pkl, constants.pkl, version, model.json, attributes.pkl).
Usage
Use this as the first step in format identification. Pass the resulting dict to identify_pytorch_file_format or check_for_corruption.
Code Reference
Source Location
- Repository: fickling
- File: fickling/polyglot.py
- Lines: L111-167
Signature
def find_file_properties(
file_path: str,
print_properties: bool = False
) -> dict:
"""Discover structural properties of a file.
Args:
file_path: Path to the file to inspect.
print_properties: Print discovered properties to stdout.
Returns:
Dict with boolean keys: is_torch_zip, is_tar,
is_valid_pickle, is_numpy, is_numpy_pickle,
is_standard_zip, is_standard_not_torch,
has_constants_pkl, has_data_pkl, has_version,
has_model_json, has_attributes_pkl.
"""
Import
from fickling.polyglot import find_file_properties
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| file_path | str | Yes | Path to the file to inspect |
| print_properties | bool | No | Print discovered properties to stdout (default: False) |
Outputs
| Name | Type | Description |
|---|---|---|
| (return) | dict | Boolean properties dict with 12 keys describing file structure |
Usage Examples
Inspect File Properties
from fickling.polyglot import find_file_properties
properties = find_file_properties("model.pt", print_properties=True)
if properties["is_torch_zip"] and properties["has_data_pkl"]:
print("Standard PyTorch v1.3 format")
elif properties["is_valid_pickle"]:
print("Legacy stacked pickle format")
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment