Skip to content

gh-141749: fix incorrect exceptions in pure Python Unpickler - #141751

Closed
literally-user wants to merge 5 commits into
python:mainfrom
literally-user:fix-issue-141749
Closed

literally-user wants to merge 5 commits into
python:mainfrom
literally-user:fix-issue-141749

Conversation

@literally-user

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

Copy link
Copy Markdown

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

bedevere-app Bot commented Nov 19, 2025

Copy link
Copy Markdown

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

bedevere-app Bot commented Nov 19, 2025

Copy link
Copy Markdown

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.

Comment thread Lib/pickle.py
assert isinstance(key, bytes_types)
dispatch[key[0]](self)
try:
dispatch[key[0]](self)

Copy link
Copy Markdown
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.

Comment thread Lib/test/test_pickle.py

unpickler = pickle._Unpickler
bad_stack_errors = (IndexError,)
bad_stack_errors = (IndexError, pickle.UnpicklingError)

Copy link
Copy Markdown
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

bedevere-app Bot commented Nov 21, 2025

Copy link
Copy Markdown

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

picnixz commented Nov 21, 2025

Copy link
Copy Markdown
Member

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