Skip to content

Conversation

@literally-user
Copy link

@literally-user literally-user commented Nov 19, 2025

Fixed incorrect exception types occurring in the CPython Unpickler implementation when loading invalid pickle data. In some cases, the CPython fallback raised internal KeyError and IndexError exceptions instead of UnpicklingError.

This PR adds correct error handling in both places so that UnpicklingError is raised consistently.

@bedevere-app
Copy link

bedevere-app bot commented Nov 19, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@bedevere-app
Copy link

bedevere-app bot commented Nov 19, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

assert isinstance(key, bytes_types)
dispatch[key[0]](self)
try:
dispatch[key[0]](self)
Copy link
Member

Choose a reason for hiding this comment

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

Do not catch a KeyError for the call. Use a temporary variable for the dispatcher first.


unpickler = pickle._Unpickler
bad_stack_errors = (IndexError,)
bad_stack_errors = (IndexError, pickle.UnpicklingError)
Copy link
Member

Choose a reason for hiding this comment

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

Shpuld we still catch IndexError now?

@bedevere-app
Copy link

bedevere-app bot commented Nov 21, 2025

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@picnixz
Copy link
Member

picnixz commented Nov 21, 2025

Ah I didn't that we had a second PR for that by the OP. Usually it is polite to ask the OP if they want to make a PR before making it one, and they did so a bit after. In this case I am actually going to close this one. Sorry.

@picnixz picnixz closed this Nov 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants