Skip to content

Commit 95b5a5d

Browse files
committed
chore: support Python 3.13, prep for 3.14
Signed-off-by: William Woodruff <william@trailofbits.com>
1 parent d3f80d2 commit 95b5a5d

File tree

4 files changed

+29
-18
lines changed

4 files changed

+29
-18
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
strategy:
1616
matrix:
17-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
17+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
1818

1919
steps:
2020
- uses: actions/checkout@v4

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Fickling can be used both as a **python library** and a **CLI**.
2222

2323
## Installation
2424

25-
Fickling has been tested on Python 3.8 through Python 3.11 and has very few dependencies.
25+
Fickling has been tested on Python 3.8 through Python 3.13 and has very few dependencies.
2626
Both the library and command line utility can be installed through pip:
2727

2828
```bash
@@ -38,7 +38,7 @@ python -m pip install fickling[torch]
3838

3939
## Securing AI/ML environments
4040

41-
Fickling can help securing AI/ML codebases by automatically scanning pickle files contained in
41+
Fickling can help securing AI/ML codebases by automatically scanning pickle files contained in
4242
models. Fickling hooks the pickle module and verifies imports made when loading a model. It only
4343
checks the imports against an allowlist of imports from ML libraries that are considered safe, and blocks files that contain other imports.
4444

@@ -50,7 +50,7 @@ import fickling
5050
fickling.hook.activate_safe_ml_environment()
5151
```
5252

53-
To remove the protection:
53+
To remove the protection:
5454

5555
```python
5656
fickling.hook.deactivate_safe_ml_environment()
@@ -82,7 +82,7 @@ raises an `UnsafeFileError` exception if malicious content is detected in the fi
8282
# This enforces safety checks every time pickle.load() is used
8383
fickling.always_check_safety()
8484

85-
# Attempt to load an unsafe file now raises an exception
85+
# Attempt to load an unsafe file now raises an exception
8686
with open("file.pkl", "rb") as f:
8787
try:
8888
pickle.load(f)
@@ -108,7 +108,7 @@ pickle.load("file.pkl")
108108
#### Option 3: check and load a single file
109109

110110
```python
111-
# Use fickling.load() in place of pickle.load() to check safety and load a single pickle file
111+
# Use fickling.load() in place of pickle.load() to check safety and load a single pickle file
112112
try:
113113
fickling.load("file.pkl")
114114
except fickling.UnsafeFileError as e:
@@ -201,8 +201,8 @@ Module(
201201

202202
### PyTorch polyglots
203203

204-
PyTorch contains multiple file formats with which one can make polyglot files, which
205-
are files that can be validly interpreted as more than one file format.
204+
PyTorch contains multiple file formats with which one can make polyglot files, which
205+
are files that can be validly interpreted as more than one file format.
206206
Fickling supports identifying, inspecting, and creating polyglots with the
207207
following PyTorch file formats:
208208

@@ -223,7 +223,7 @@ following PyTorch file formats:
223223
>> torch.save(model, "mobilenet.pth")
224224
>> fickled_model = PyTorchModelWrapper("mobilenet.pth")
225225
>> print(fickled_model.formats)
226-
Your file is most likely of this format: PyTorch v1.3
226+
Your file is most likely of this format: PyTorch v1.3
227227
['PyTorch v1.3']
228228
```
229229

fickling/fickle.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
import struct
55
import sys
66
from abc import ABC, abstractmethod
7-
from collections.abc import MutableSequence, Sequence
7+
from collections.abc import Buffer, MutableSequence, Sequence
88
from enum import Enum
99
from io import BytesIO
1010
from pickletools import OpcodeInfo, genops, opcodes
1111
from typing import (
1212
Any,
1313
BinaryIO,
14-
ByteString,
1514
Dict,
1615
FrozenSet,
1716
Generic,
@@ -715,15 +714,15 @@ def opcodes(self) -> Iterator[Opcode]:
715714
return iter(self)
716715

717716
@staticmethod
718-
def make_stream(data: Union[ByteString, BinaryIO]) -> BinaryIO:
719-
if isinstance(data, (bytes, bytearray, ByteString)):
717+
def make_stream(data: Union[Buffer, BinaryIO]) -> BinaryIO:
718+
if isinstance(data, (bytes, bytearray, Buffer)):
720719
data = BytesIO(data)
721720
elif (not hasattr(data, "seekable") or not data.seekable()) and hasattr(data, "read"):
722721
data = BytesIO(data.read())
723722
return data
724723

725724
@staticmethod
726-
def load(pickled: Union[ByteString, BinaryIO]) -> "Pickled":
725+
def load(pickled: Union[Buffer, BinaryIO]) -> "Pickled":
727726
pickled = Pickled.make_stream(pickled)
728727
first_pos = pickled.tell()
729728
opcodes: List[Opcode] = []
@@ -1733,7 +1732,7 @@ def __len__(self) -> int:
17331732
return len(self.pickled)
17341733

17351734
@staticmethod
1736-
def load(pickled: Union[ByteString, BinaryIO]) -> "StackedPickle":
1735+
def load(pickled: Union[Buffer, BinaryIO]) -> "StackedPickle":
17371736
pickled = Pickled.make_stream(pickled)
17381737
pickles: List[Pickled] = []
17391738
while True:

pyproject.toml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,26 @@ classifiers = [
1717
"Programming Language :: Python :: 3 :: Only",
1818
"Topic :: Utilities",
1919
]
20-
dependencies = ["astunparse ~= 1.6.3", "stdlib_list ~= 0.10.0"]
20+
dependencies = ["astunparse ~= 1.6.3", "stdlib_list ~= 0.11.1"]
2121
requires-python = ">=3.8"
2222

2323
[project.optional-dependencies]
2424
torch = ["torch >= 2.1.0", "torchvision >= 0.16.1"]
2525
lint = ["black", "mypy", "ruff==0.5.4"]
26-
test = ["pytest", "pytest-cov", "coverage[toml]", "torch >= 2.1.0", "torchvision >= 0.16.1"]
27-
dev = ["build", "fickling[lint,test]", "twine", "torch >= 2.1.0", "torchvision >= 0.16.1"]
26+
test = [
27+
"pytest",
28+
"pytest-cov",
29+
"coverage[toml]",
30+
"torch >= 2.1.0",
31+
"torchvision >= 0.16.1",
32+
]
33+
dev = [
34+
"build",
35+
"fickling[lint,test]",
36+
"twine",
37+
"torch >= 2.1.0",
38+
"torchvision >= 0.16.1",
39+
]
2840
examples = ["numpy", "pytorchfi"]
2941

3042
[project.scripts]

0 commit comments

Comments
 (0)