Skip to content

Add more tests for pickle and fix error messages #122311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
serhiy-storchaka opened this issue Jul 26, 2024 · 0 comments
Closed

Add more tests for pickle and fix error messages #122311

serhiy-storchaka opened this issue Jul 26, 2024 · 0 comments
Assignees
Labels
3.12 only security fixes 3.13 bugs and security fixes 3.14 bugs and security fixes tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented Jul 26, 2024

Bug report

Much error generating code in the pickle module is not tested at all. As result, not only exception types and messages can differ between Python and C implementations, but other bugs are left unnoticed:

  • NameError in formatting one of error messages.
  • "Can't pickle" in the error message during unpickling.
  • Error message including the repr of wrong object.
  • Some errors are only detected in one of implementations (Python or C).
  • Crash in untested corner case (Crash after error in PickleBuffer #122306).

I am going to add more tests and fix the most odious errors. This will be backported to 3.12 and 3.13, but the backport to 3.12 will have more lenient variants of tests. Late, I will unify and improve other error messages (this is for main only).

Linked PRs

@serhiy-storchaka serhiy-storchaka added type-bug An unexpected behavior, bug, or error tests Tests in the Lib/test dir 3.12 only security fixes 3.13 bugs and security fixes 3.14 bugs and security fixes labels Jul 26, 2024
@serhiy-storchaka serhiy-storchaka self-assigned this Jul 26, 2024
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Jul 26, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jul 26, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jul 26, 2024
serhiy-storchaka added a commit that referenced this issue Jul 26, 2024
serhiy-storchaka added a commit that referenced this issue Jul 26, 2024
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Jul 28, 2024
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Jul 28, 2024
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Jul 28, 2024
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Jul 28, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jul 28, 2024
(cherry picked from commit bc93923)

Co-authored-by: Serhiy Storchaka <[email protected]>
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Jul 28, 2024
(cherry picked from commit bc93923)

Co-authored-by: Serhiy Storchaka <[email protected]>
serhiy-storchaka added a commit that referenced this issue Jul 28, 2024
(cherry picked from commit bc93923)

Co-authored-by: Serhiy Storchaka <[email protected]>
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Jul 28, 2024
serhiy-storchaka added a commit that referenced this issue Jul 28, 2024
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Jul 29, 2024
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Jul 29, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jul 29, 2024
(cherry picked from commit 3b034d2)

Co-authored-by: Serhiy Storchaka <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jul 29, 2024
(cherry picked from commit 3b034d2)

Co-authored-by: Serhiy Storchaka <[email protected]>
serhiy-storchaka added a commit that referenced this issue Jul 29, 2024
serhiy-storchaka added a commit that referenced this issue Jul 29, 2024
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Jul 29, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jul 29, 2024
(cherry picked from commit 68840e9)

Co-authored-by: Serhiy Storchaka <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jul 29, 2024
(cherry picked from commit 68840e9)

Co-authored-by: Serhiy Storchaka <[email protected]>
serhiy-storchaka added a commit that referenced this issue Jul 29, 2024
(cherry picked from commit 68840e9)

Co-authored-by: Serhiy Storchaka <[email protected]>
serhiy-storchaka added a commit that referenced this issue Jul 29, 2024
(cherry picked from commit 68840e9)

Co-authored-by: Serhiy Storchaka <[email protected]>
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Aug 7, 2024
* Raise PicklingError instead of UnicodeEncodeError, ValueError
  and AttributeError in both implementations.
* Chain the original exception to the pickle-specific one as __context__.
* Include the error message of ImportError and some AttributeError in
  the PicklingError error message.
* Unify error messages between Python and C implementations.
* Refer to documented __reduce__ and __newobj__ callables instead of
  internal methods (e.g. save_reduce()) or pickle opcodes (e.g. NEWOBJ).
* Include more details in error messages (what expected, what got).
* Avoid including a potentially long repr of an arbitrary object in
  error messages.
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Aug 7, 2024
* Raise PicklingError instead of UnicodeEncodeError, ValueError
  and AttributeError in both implementations.
* Chain the original exception to the pickle-specific one as __context__.
* Include the error message of ImportError and some AttributeError in
  the PicklingError error message.
* Unify error messages between Python and C implementations.
* Refer to documented __reduce__ and __newobj__ callables instead of
  internal methods (e.g. save_reduce()) or pickle opcodes (e.g. NEWOBJ).
* Include more details in error messages (what expected, what got).
* Avoid including a potentially long repr of an arbitrary object in
  error messages.
serhiy-storchaka added a commit that referenced this issue Sep 9, 2024
* Raise PicklingError instead of UnicodeEncodeError, ValueError
  and AttributeError in both implementations.
* Chain the original exception to the pickle-specific one as __context__.
* Include the error message of ImportError and some AttributeError in
  the PicklingError error message.
* Unify error messages between Python and C implementations.
* Refer to documented __reduce__ and __newobj__ callables instead of
  internal methods (e.g. save_reduce()) or pickle opcodes (e.g. NEWOBJ).
* Include more details in error messages (what expected, what got).
* Avoid including a potentially long repr of an arbitrary object in
  error messages.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 only security fixes 3.13 bugs and security fixes 3.14 bugs and security fixes tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
Projects
Status: Done
Development

No branches or pull requests

1 participant