Skip to content

Conversation

@serhiy-storchaka
Copy link
Member

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

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

@vstinner vstinner left a comment

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 on lines +2206 to +2207
with self.assertRaises(exc):
self.dumps(MyList, proto)
Copy link
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
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

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

bedevere-app bot commented Aug 29, 2024

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

bedevere-app bot commented Aug 29, 2024

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