Tolerate a missing _cloudpickle_submodules key in _function_setstate - #596
Open
soodoku wants to merge 1 commit into
Open
Tolerate a missing _cloudpickle_submodules key in _function_setstate#596soodoku wants to merge 1 commit into
_cloudpickle_submodules key in _function_setstate#596soodoku wants to merge 1 commit into
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.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.