is_likely_safe() only checks the first pickle stream in a file
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 30/100
Research direction
Start at is_likely_safe() in fickling/analysis.py (around lines 686-692), which calls Pickled.load(..., fail_on_decode_error=False) and so reads only the first stream. Compare with how fickling/cli.py:312 and fickling/loader.py:246 use StackedPickle.load(). Run the reproducer in the issue, which writes a stacked file and calls is_likely_safe(), and confirm it returns False once every stream is checked. Done means is_likely_safe() agrees with the CLI on stacked and legacy PyTorch files. A fix PR is reportedly under way but is not linked, and the report is under embargo, so check with maintainers before starting.
Written by the indexing model from the issue text.
Description
fickling.is_likely_safe(filepath) (fickling/analysis.py:686-692) reads the file with Pickled.load(f, fail_on_decode_error=False), which stops at the first STOP opcode. Later pickle streams in the same file are not decoded or passed to check_safety(), so the result depends on the first stream only. The CLI safety check (fickling/cli.py:312) and fickling.loader (fickling/loader.py:246) read the whole file with StackedPickle.load(), so they can disagree with is_likely_safe() on the same file.
Reproducer with the stdlib pickle module and the opcode API (nothing is unpickled):
import pickle
import tempfile
from pathlib import Path
import fickling
import fickling.fickle as op
from fickling.analysis import check_safety
from fickling.fickle import Pickled
second = Pickled(
[
op.Proto.create(4),
op.ShortBinUnicode("os"),
op.ShortBinUnicode("system"),
op.StackGlobal(),
op.Stop(),
]
)
print(check_safety(second).severity) # LIKELY_OVERTLY_MALICIOUS on its own
with tempfile.TemporaryDirectory() as d:
path = Path(d) / "stacked.pkl"
path.write_bytes(pickle.dumps({"label": 1}) + second.dumps())
print(fickling.is_likely_safe(str(path))) # True on master
The same applies to PyTorch files in the legacy non-zip format, which hold five pickle streams where the first is only the magic number: is_likely_safe() returns True for them whatever the object stream contains, while fickling --check-safety on the same file exits 1.
Reported privately as GHSA-vv58-2pw5-4fcf and opened here at the maintainers' request. A fix is in a pull request that switches is_likely_safe() to StackedPickle.load() and requires every stream to be rated LIKELY_SAFE.
- Dominant language
- Python
- Stars
- 678
- Forks
- 89
- Avg merge
- 41m
- Merged PRs (30d)
- 14
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from trailofbits/fickling
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
trailofbits/fickling#355 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 64/100
trailofbits/fickling#322 · 3 comments ·
Maintainers usually reply within 1 day
-
stdlib check depends on the scanner's Python versionPossibly taken @thomas-chauchefoin-tob claimed this 117 days ago. Open
trailofbits/fickling#311 · 1 assignee ·
Maintainers usually reply within 1 day
-
Further align the CLI and Python APIPossibly taken @dguido claimed this 305 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 30/100
trailofbits/fickling#101 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
trailofbits/fickling#97 · 1 comment ·
Maintainers usually reply within 1 day
All issues in trailofbits/fickling
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
UKGovernmentBEIS/inspect_ai#6733 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
ProyectoRespira/respira-webapp#334 ·
Maintainers usually reply within 1 day
-
bug security-alert
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
spectrayan/carefold#391 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Jakeschincariol/instagram-agent-skill#83 ·
Maintainers usually reply within 10 days
-
Difficulty 1/5 Under an hour Newbie friendliness 64/100