Commit graph

256 commits

Author SHA1 Message Date
Miss Islington (bot)
0e969fe843
[3.14] gh-135321: Always raise a correct exception for BINSTRING argument > 0x7fffffff in pickle (GH-135322) (GH-135382)
Some checks are pending
Tests / Windows MSI (push) Blocked by required conditions
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / Check if the ABI has changed (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / Cross build Linux (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run
(cherry picked from commit 2b8b4774d2)

Co-authored-by: Justin Applegate <70449145+Legoclones@users.noreply.github.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2025-06-11 14:01:15 +03:00
Miss Islington (bot)
db98e0bb12
[3.14] gh-71339: Use new assertion methods in tests (GH-129046) (GH-134498)
(cherry picked from commit 2602d8ae98)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2025-05-22 10:42:50 +00:00
Miss Islington (bot)
dc1a4dda88
[3.14] gh-131031: Fix test_pickle when invoked directly (GH-133356) (GH-133673)
(cherry picked from commit e15bbfafbc)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2025-05-08 15:19:58 +00:00
Justin Applegate
ce76b547f9
gh-126992: Change pickle code to base 10 for load_long and load_int (GH-127042)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-12-11 12:37:59 +00:00
Serhiy Storchaka
addb225f38
gh-126991: Add tests for unpickling bad object state (GH-127031)
This catches a memory leak in loading the BUILD opcode.
2024-11-20 17:31:50 +02:00
Serhiy Storchaka
19984fe024
gh-53203: Improve tests for strptime() (GH-125090)
Run them with different locales and different date and time.

Add the @run_with_locales() decorator to run the test with multiple
locales.

Improve the run_with_locale() context manager/decorator -- it now
catches only expected exceptions and reports the test as skipped if no
appropriate locale is available.
2024-10-08 08:40:02 +00:00
Alex Waygood
8a2baedc4b
Bump Ruff to 0.6.7 (#124384) 2024-09-23 22:19:35 +00:00
Serhiy Storchaka
a1dbf2ea69
gh-77894: Fix a crash when the GC breaks a loop containing a memoryview (GH-123898)
Now a memoryview object can only be cleared if there are no buffers
that refer it.
2024-09-11 12:05:46 +03:00
Serhiy Storchaka
c0c2aa7644
gh-122213: Add notes for pickle serialization errors (GH-122214)
This allows to identify the source of the error.
2024-09-09 21:28:55 +03:00
algonell
9017b95ff2
Fix typos (#123775) 2024-09-09 14:58:26 +02:00
Serhiy Storchaka
b2a8c38bb2
gh-122311: Improve and unify pickle errors (GH-122771)
* 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.
2024-09-09 15:04:51 +03:00
Serhiy Storchaka
0c3ea30238
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.
2024-08-29 08:26:16 +03:00
Serhiy Storchaka
1bb955a2fe
gh-122459: Optimize pickling by name objects without __module__ (GH-122460) 2024-08-05 16:21:32 +03:00
Serhiy Storchaka
0697188084
gh-122311: Add more tests for error messages in pickle (GH-122373) 2024-07-29 13:40:16 +03:00
Serhiy Storchaka
3b034d26eb
gh-122311: Fix some error messages in pickle (GH-122386) 2024-07-29 11:49:13 +03:00
Serhiy Storchaka
bc93923a2d
gh-122311: Add more tests for pickle (GH-122376) 2024-07-28 11:33:17 +03:00
Serhiy Storchaka
dc07f65a53
gh-82951: Fix serializing by name in pickle protocols < 4 (GH-122149)
Serializing objects with complex __qualname__ (such as unbound methods and
nested classes) by name no longer involves serializing parent objects by value
in pickle protocols < 4.
2024-07-25 08:45:19 +00:00
Bénédikt Tran
7595e6743a
gh-120380: fix Python implementation of pickle.Pickler for bytes and bytearray objects in protocol version 5. (GH-120422) 2024-06-21 14:22:38 +02:00
Brett Cannon
8aa126354d
GH-111802: set a low recursion limit for test_bad_getattr() in test.pickletester (GH-113996) 2024-01-12 14:14:09 -08:00
Jeff Allen
08398631a0
gh-113028: Correctly memoize str in pickle when escapes added (GH-113436)
This fixes a divergence between the Python and C implementations of pickle
for protocol 0, such that it pickle.py fails to re-use the first pickled
representation of strings involving characters that have to be escaped.
2023-12-24 11:43:44 +02:00
Zackery Spytz
058444308a
gh-82565: Add tests for pickle and unpickle with bad files (GH-16606) 2023-12-01 13:36:37 +00:00
Pieter Eendebak
85a5d3dbe1
gh-93627: Align Python implementation of pickle with C implementation of pickle (GH-103035)
If a method like __reduce_ex_ or __reduce__ is set to None, a TypeError is raised.
2023-09-10 10:06:08 +03:00
Serhiy Storchaka
f3ba0a74cd
gh-108416: Mark slow test methods with @requires_resource('cpu') (GH-108421)
Only mark tests which spend significant system or user time,
by itself or in subprocesses.
2023-09-02 07:45:34 +03:00
Serhiy Storchaka
b98d2d31bf
gh-100129: Add tests for pickling all builtin types and functions (GH-100142) 2022-12-21 16:31:22 +02:00
Serhiy Storchaka
77f0249308
gh-95196: Disable incorrect pickling of the C implemented classmethod descriptors (GH-96383) 2022-10-05 14:21:16 +03:00
Dennis Sweeney
4c496f1f11
gh-92930: _pickle.c: Acquire strong references before calling save() (GH-92931) 2022-06-10 21:50:11 -04:00
Christian Heimes
2b16a08bc7
bpo-40280: Detect missing threading on WASM platforms (GH-32352)
Co-authored-by: Brett Cannon <brett@python.org>
2022-04-07 09:22:47 +02:00
Serhiy Storchaka
884eba3c76
bpo-26579: Add object.__getstate__(). (GH-2821)
Copying and pickling instances of subclasses of builtin types
bytearray, set, frozenset, collections.OrderedDict, collections.deque,
weakref.WeakSet, and datetime.tzinfo now copies and pickles instance attributes
implemented as slots.
2022-04-06 20:00:14 +03:00
Dennis Sweeney
d56375a0dd
bpo-30570: Fix segfault on buildbots caused by stack overflow from recursion in tests (GH-29258)
* Don't stackoveflow on debug builds

* Also catch the pickletester case
2021-10-28 11:11:18 +01:00
Christian Clauss
745c9d9dfc
Fix typos in the Lib directory (GH-28775)
Fix typos in the Lib directory as identified by codespell.

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
2021-10-06 16:13:48 -07:00
Serhiy Storchaka
e6ba992288
bpo-45229: Make pickle tests discoverable (GH-28467) 2021-09-20 18:21:33 +03:00
Carl Friedrich Bolz-Tereick
1e9f093309
bpo-43907: add missing memoize call in pure python pickling of bytearray (GH-25501) 2021-04-23 23:27:14 +02:00
Serhiy Storchaka
a25011be8c
bpo-42809: Improve pickle tests for recursive data. (GH-24060) 2021-01-02 19:32:47 +02:00
Serhiy Storchaka
8cd1dbae32
bpo-41052: Fix pickling heap types implemented in C with protocols 0 and 1 (GH-22870) 2020-10-24 21:14:23 +03:00
Serhiy Storchaka
4f309abf55
bpo-41288: Fix a crash in unpickling invalid NEWOBJ_EX. (GH-21458)
Automerge-Triggered-By: @tiran
2020-07-13 05:49:26 -07:00
Hai Shi
883bc63833
bpo-40275: Use new test.support helper submodules in tests (GH-21314) 2020-07-06 11:12:49 +02:00
Victor Stinner
8362893e3f
bpo-41003: Fix test_copyreg when numpy is installed (GH-20935)
Fix test_copyreg when numpy is installed: test.pickletester now
saves/restores warnings.filters when importing numpy, to ignore
filters installed by numpy.

Add the save_restore_warnings_filters() function to the
test.support.warnings_helper module.
2020-06-17 18:07:13 +02:00
Hai Shi
e80697d687
bpo-40275: Adding threading_helper submodule in test.support (GH-20263) 2020-05-28 00:10:27 +02:00
Antoine Pitrou
9f37872e30
bpo-39681: Fix C pickle regression with minimal file-like objects (#18592)
Fix a regression where the C pickle module wouldn't allow unpickling from a
file-like object that doesn't expose a readinto() method.
2020-02-23 23:33:53 +01:00
Pierre Glaser
0f2f35e15f
bpo-39492: Fix a reference cycle between reducer_override and a Pickler instance (GH-18266)
This also needs a backport to 3.8


https://bugs.python.org/issue39492



Automerge-Triggered-By: @pitrou
2020-02-02 10:55:21 -08:00
Claudiu Popa
6f03b236c1 bpo-38876: Raise pickle.UnpicklingError when loading an item from memo for invalid input (GH-17335)
The previous code was raising a `KeyError` for both the Python and C implementation.
This was caused by the specified index of an invalid input which did not exist
in the memo structure, where the pickle stores what objects it has seen.
The malformed input would have caused either a `BINGET` or `LONG_BINGET` load
from the memo, leading to a `KeyError` as the determined index was bogus.

https://bugs.python.org/issue38876



https://bugs.python.org/issue38876
2019-11-24 11:15:08 -08:00
Neil Schemenauer
eca7ffc61c
Don't skip pickle check_frame_opcodes() (GH-15025)
This looks like the only place that proto 4 framing gets exercised
so leave it as part of the PGO task.
2019-07-30 12:08:17 -07:00
Neil Schemenauer
52a48e62c6
bpo-37707: Exclude expensive unit tests from PGO task (GH-15009)
Mark some individual tests to skip when --pgo is used.  The tests
marked increase the PGO task time significantly and likely don't
help improve optimization of the final executable.
2019-07-30 11:08:18 -07:00
Markus Mohrhard
898318b53d bpo-37502: handle default parameter for buffers argument of pickle.loads correctly (GH-14593) 2019-07-25 18:00:34 +02:00
Serhiy Storchaka
38ab7d4721
bpo-31829: Make protocol 0 pickles be loadable in text mode in Python 2. (GH-11859)
Escape ``\r``, ``\0`` and ``\x1a`` (end-of-file on Windows) in Unicode strings.
2019-05-31 11:29:39 +03:00
Antoine Pitrou
91f4380ced
bpo-36785: PEP 574 implementation (GH-7076) 2019-05-26 17:10:09 +02:00
Pierre Glaser
289f1f80ee bpo-35900: Enable custom reduction callback registration in _pickle (GH-12499)
Enable custom reduction callback registration for functions and classes in
_pickle.c, using the new Pickler's attribute ``reducer_override``.
2019-05-08 23:08:25 +02:00
Pierre Glaser
65d98d0f53 bpo-35900: Add a state_setter arg to save_reduce (GH-12588)
Allow reduction methods to return a 6-item tuple where the 6th item specifies a
custom state-setting method that's called instead of the regular
``__setstate__`` method.
2019-05-08 21:40:25 +02:00
penguindustin
9646630895 bpo-36766: Typos in docs and code comments (GH-13116) 2019-05-06 14:57:17 -04:00
Anthony Sottile
8377cd4fcd Clean up code which checked presence of os.{stat,lstat,chmod} (#11643) 2019-02-25 23:32:27 +01:00