Repository navigation
Conversation
_function_setstate pops "_cloudpickle_submodules" from the slotstate without a default, so a payload that does not carry that key raises an opaque KeyError from inside pickle.loads rather than a normal unpickling failure. Before c6f8cd4 the code guarded this: if '_cloudpickle_submodules' in state: state.pop('_cloudpickle_submodules') That commit consolidated the module and the surviving version pops unconditionally. Restore the tolerance by passing a default. Valid cloudpickle payloads always set the key, so this is a no-op for them. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
If I understand the problem correctly, this fix is about making If that's the case, I would rather use a non-regression test that test this explicitly (using only public API) and update the changelog entry accordingly. |
|
Thanks for taking a look, @ogrisel, and sorry for the slow follow-up. Your question made me check the premise more carefully, and I think you're right to be skeptical: a payload written by |
|
Thanks for the followup. I don't see the pount of the original issue. |
Fixes #593.
_function_setstatepops_cloudpickle_submodulesfrom the slotstate without a default, so a payload that does not carry that key raisesKeyError: '_cloudpickle_submodules'from insidepickle.loads, rather than a normal unpickling failure.This restores handling that used to be there. Before c6f8cd4 the code read:
That commit ("code clean-up after EOLed Python 3.6 and 3.7") consolidated the module and the surviving version pops unconditionally. Valid cloudpickle payloads always set the key, so this changes nothing for them — it only affects payloads that omit it.
I've deliberately left the issue's CVE framing aside:
pickle.loadson untrusted input already permits arbitrary code execution, so I don't think aKeyErrorthere is a security boundary. The narrow case for this change is just that a malformed payload should not crash with an opaqueKeyErrorfrom the middle of apop.If you'd rather have this raise an explicit
pickle.UnpicklingErrorwith a clear message than tolerate the omission, that's a one-line change and I'm happy to switch.Scope of the public API
On current upstream,
cloudpickle.load is pickle.loadandcloudpickle.loads is pickle.loads. Standard-library round trips of a dictionary and an importable function both pass before this change. The proposed change only concerns restoration of dynamic function state that omits the submodule list. A test using ordinarypickle.dumpwould already pass on the base branch.Verification
Run against a Python 3.12 venv (
dev-requirements.txtpins numpy topython_version <= '3.12', so 3.12 exercises more of the suite than 3.14 would):266 passed, 10 skipped, 2 xfailed267 passed, 10 skipped, 2 xfailedThe only delta is the new test. It fails on master with
KeyError: '_cloudpickle_submodules'atcloudpickle/cloudpickle.py:1156and passes with the fix.black25.9.0 (the version pinned in.pre-commit-config.yaml) reports both touched files unchanged.ruff check cloudpickle testsreports the same 81 pre-existing findings before and after, none on the touched lines.The changelog entry links the issue since the PR number isn't known yet — happy to swap it for the PR link.