Skip to content

Restrict load_pickle to numpy and builtin containers - #72

Merged
rossant merged 6 commits into
masterfrom
fix/load-pickle-restricted
Nov 26, 2026
Merged

rossant merged 6 commits into
masterfrom
fix/load-pickle-restricted

Conversation

@oliche

@oliche oliche commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

load_pickle() previously delegated to unrestricted joblib.load(). It now uses a restricted joblib unpickler for uncompressed files containing plain Python containers and supported NumPy arrays, scalars, and dtypes.

Custom globals, pickle extensions (including cached extensions), and all object-dtype arrays—including harmless ones—are rejected with pickle.UnpicklingError. Compressed files are rejected with ValueError. This is not support for filtering arbitrary objects inside object arrays.

The implementation requires joblib>=1.5; the requirement is recorded in pyproject.toml and uv.lock. save_pickle() retains joblib's full writer behavior, so compressed files, custom objects, and object arrays it writes cannot be read back by load_pickle(). README and changelog describe supported round trips and migration.

Regression tests cover supported containers, NumPy scalar/dtype and array formats, direct/nested malicious payloads, harmless and malicious object arrays, cached EXT1/EXT2/EXT4 payloads, compressed formats, and object-array conversion. All nine CI checks pass on head cd3b000e97d0e4bbd44750aeea57323dbc22c863 against the original stack base.

Stacked on #71. After #71 merges, retarget this PR to master, verify only pickle-related changes remain, and require passing CI on the resulting merge candidate. Companion Phy work will verify persisted cache compatibility before release. No package publication is part of this PR.

@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.

@oliche
oliche force-pushed the fix/load-pickle-restricted branch from 7f9d152 to 206a60a Compare November 18, 2026 10:46

@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.

The requested format restrictions and compatibility changes are addressed. The joblib requirement matches the implementation, and CI is green for this commit.

Base automatically changed from fix/read-python-safe-eval to master November 26, 2026 18:48
@rossant
rossant force-pushed the fix/load-pickle-restricted branch from cd3b000 to 497069c Compare November 26, 2026 18:48
Restore the exact reviewed tree, retaining the rewritten branch and original reviewed history.
@rossant
rossant merged commit 86216fb into master Nov 26, 2026
9 checks passed
@oliche
oliche deleted the fix/load-pickle-restricted branch November 30, 2026 11:31
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