Skip to content

gh-123431: Harmonize extension code checks in pickle#123434

Merged
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:pickle-bad-extension-code
Aug 29, 2024
Merged

gh-123431: Harmonize extension code checks in pickle#123434
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:pickle-bad-extension-code

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Aug 28, 2024

Copy link
Copy Markdown
Member

This checks are redundant in normal circumstances and can only work if the extension registry was intentionally broken.

  • The Python implementation now raises exception for the extension code with false boolean value.
  • Simplify the C code. RuntimeError is now raised in explicit checks.
  • Add many tests.

This checks are redundant in normal circumstances and can only work if
the extension registry was intentionally broken.

* The Python implementation now raises exception for the extension code
  with false boolean value.
* Simplify the C code. RuntimeError is now raised in explicit checks.
* Add many tests.

@vstinner vstinner left a comment

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.

LGTM. New tests cover changes, and the modified code looks correct to me.

Comment thread Lib/test/pickletester.py
Comment on lines +2206 to +2207
with self.assertRaises(exc):
self.dumps(MyList, proto)

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.

Suggested change
with self.assertRaises(exc):
self.dumps(MyList, proto)
with self.subTest(proto=proto):
with self.assertRaises(exc):
self.dumps(MyList, proto)

Just to know which protocol failed (I see tabs and spaces on GH so I hope that if you commit my suggestions, it will be normalized...)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is not important, because the code is the same for all protocols >= 2. Original tests for this feature only use protocol 2.

On other hand, using subTest() will produce worse tracebacks if some test fails. Currently the traceback contains the line with the check() call. subTest() truncates the traceback.

@serhiy-storchaka serhiy-storchaka merged commit 0c3ea30 into python:main Aug 29, 2024
@miss-islington-app

Copy link
Copy Markdown

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13.
🐍🍒⛏🤖

@serhiy-storchaka serhiy-storchaka deleted the pickle-bad-extension-code branch August 29, 2024 05:26
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 29, 2024
…123434)

This checks are redundant in normal circumstances and can only work if
the extension registry was intentionally broken.

* The Python implementation now raises exception for the extension code
  with false boolean value.
* Simplify the C code. RuntimeError is now raised in explicit checks.
* Add many tests.
(cherry picked from commit 0c3ea30)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@bedevere-app

bedevere-app Bot commented Aug 29, 2024

Copy link
Copy Markdown

GH-123459 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Aug 29, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 29, 2024
…123434)

This checks are redundant in normal circumstances and can only work if
the extension registry was intentionally broken.

* The Python implementation now raises exception for the extension code
  with false boolean value.
* Simplify the C code. RuntimeError is now raised in explicit checks.
* Add many tests.
(cherry picked from commit 0c3ea30)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@bedevere-app

bedevere-app Bot commented Aug 29, 2024

Copy link
Copy Markdown

GH-123460 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.12 only security fixes label Aug 29, 2024
Yhg1s pushed a commit that referenced this pull request Sep 2, 2024
… (#123459)

gh-123431: Harmonize extension code checks in pickle (GH-123434)

This checks are redundant in normal circumstances and can only work if
the extension registry was intentionally broken.

* The Python implementation now raises exception for the extension code
  with false boolean value.
* Simplify the C code. RuntimeError is now raised in explicit checks.
* Add many tests.
(cherry picked from commit 0c3ea30)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
ambv pushed a commit that referenced this pull request Sep 6, 2024
… (#123460)

This checks are redundant in normal circumstances and can only work if
the extension registry was intentionally broken.

(cherry picked from commit 0c3ea30)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
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.

3 participants