Skip to content

Restrict load_pickle to numpy and builtin containers - #72

Open
oliche wants to merge 2 commits into
fix/read-python-safe-evalfrom
fix/load-pickle-restricted
Open

oliche wants to merge 2 commits into
fix/read-python-safe-evalfrom
fix/load-pickle-restricted

Conversation

@oliche

@oliche oliche commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Stacked on #71.

load_pickle used joblib.load, which runs arbitrary code from an untrusted pickle. It now uses a restricted joblib unpickler that only allows numpy arrays/dtypes/scalars and a few builtin types; anything else raises pickle.UnpicklingError. Object-dtype arrays are covered too. Requires joblib>=1.6 (pinned in requirements.txt and environment.yml), which routes nested object-array unpickling through find_class.

Behaviour changes: load_pickle no longer loads arbitrary objects, compressed files or memory-mapped arrays. save_pickle is unchanged, so existing files written by it still load.

Tests check that arrays and containers round-trip and that malicious payloads (bare, nested, hidden in an object array) are refused without executing.

@oliche
oliche requested a review from rossant November 5, 2026 18:48
@oliche
oliche added this pull request to stack #73 November 5, 2026 18:48

@rossant rossant left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tackling this too! As far as I remember, Phy doesn’t use object-dtype arrays, so explicitly rejecting them seems reasonable.

Could you document that restriction and add a test rejecting a harmless object array? The current malicious object-array test fails at NumPy reconstruction, before reaching the malicious element, so it shouldn’t imply that filtering inside object arrays is supported.

Please also check the supported save_pickle output formats, including compression, and narrow the compatibility claims accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants