-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Open
Labels
3.12only security fixesonly security fixes3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixesdocsDocumentation in the Doc dirDocumentation in the Doc dirstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
When pickling a container object. The pickler class will store child-objects to its self.memo even if the container could not be fully pickled (and not written to the output).
This can cause references to memo objects that are not in the output stream.
import sys
import pickle
import io
buf = io.BytesIO()
pickler = pickle.Pickler(buf)
i_will_be_memorized = 'qqqqqqqqqqqq'
i_cant_be_pickled = sys
try:
pickler.dump([i_will_be_memorized, i_cant_be_pickled])
except TypeError:
# i_will_be_memorized is now in pickler memory despite the exception
pass
# this dump will use the memo
pickler.dump(i_will_be_memorized)
data = buf.getbuffer().tobytes()
# so this will fail with:
# _pickle.UnpicklingError: Memo value not found at index 1
pickle.loads(data)CPython versions tested on:
3.12
Operating systems tested on:
Windows
Linked PRs
Metadata
Metadata
Assignees
Labels
3.12only security fixesonly security fixes3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixesdocsDocumentation in the Doc dirDocumentation in the Doc dirstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Projects
Status
No status
Status
Todo