Skip to content
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

gh-105375: Explicitly initialise all {Pickler,Unpickler}Object fields #105686

Merged
merged 2 commits into from Jun 12, 2023

Conversation

erlend-aasland
Copy link
Contributor

@erlend-aasland erlend-aasland commented Jun 12, 2023

PyObject_GC_New() only initialises the object header. All other fields
must be explicitly initialised to prevent manipulation of uninitialised
fields in dealloc.

Align initialisation order with the layout of the object structs.

…fields

PyObject_GC_New() only initialises the object header. All other fields
must be explicitly initialised to prevent manipulation of uninitialised
fields in dealloc.

Align initialisation order with the layout of the object structs.
- Prepare memory allocations and new objects before calling PyObject_GC_New()
- Initialise all fields at once using a series of assignments only
- Use error labels for clarity
Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

I think that it is enough to set output_buffer = NULL.

@erlend-aasland
Copy link
Contributor Author

I think that it is enough to set output_buffer = NULL.

You also need to adjust _Unpickler_New(): The minimal solution is setting self->output_buffer = NULL and also for example self->stack = NULL in _Unpickler_New(). I still think this PR is better, since it makes for cleaner error handling and improved maintainability. I'm not going to push it, though; I can live with the minimal solution :)

@erlend-aasland erlend-aasland merged commit ca3cc4b into python:main Jun 12, 2023
21 checks passed
@miss-islington
Copy link
Contributor

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

@erlend-aasland erlend-aasland deleted the fix-gh-105475 branch June 12, 2023 21:35
@miss-islington
Copy link
Contributor

Sorry, @erlend-aasland, I could not cleanly backport this to 3.11 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker ca3cc4b95d66f7527ebe0ba4cdb1907082d9bfc8 3.11

@bedevere-bot
Copy link

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

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 12, 2023
…fields (pythonGH-105686)

All fields must be explicitly initialised to prevent manipulation of
uninitialised fields in dealloc.

Align initialisation order with the layout of the object structs.
(cherry picked from commit ca3cc4b)

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
@bedevere-bot bedevere-bot removed the needs backport to 3.12 bug and security fixes label Jun 12, 2023
erlend-aasland added a commit to erlend-aasland/cpython that referenced this pull request Jun 12, 2023
…Object fields (python#105686)

All fields must be explicitly initialised to prevent manipulation of
uninitialised fields in dealloc.

Align initialisation order with the layout of the object structs.

(cherry picked from commit ca3cc4b)

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
@bedevere-bot
Copy link

GH-105711 is a backport of this pull request to the 3.11 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Jun 12, 2023
@erlend-aasland
Copy link
Contributor Author

Thanks for the review!

erlend-aasland added a commit that referenced this pull request Jun 12, 2023
… fields (GH-105686) (#105710)

All fields must be explicitly initialised to prevent manipulation of
uninitialised fields in dealloc.

Align initialisation order with the layout of the object structs.

(cherry picked from commit ca3cc4b)

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
carljm added a commit to carljm/cpython that referenced this pull request Jun 12, 2023
* main:
  pythongh-105540: Fix code generator tests (python#105707)
  pythongh-105375: Explicitly initialise all {Pickler,Unpickler}Object fields (python#105686)
  pythongh-105331: Change `asyncio.sleep` to raise ``ValueError` for nan (python#105641)
  Remove support for legacy bytecode instructions (python#105705)
kumaraditya303 pushed a commit that referenced this pull request Jun 13, 2023
… fields (#105686) (#105711)

* [3.11] gh-105375: Explicitly initialise all {Pickler,Unpickler}Object fields (#105686)

All fields must be explicitly initialised to prevent manipulation of
uninitialised fields in dealloc.

Align initialisation order with the layout of the object structs.

(cherry picked from commit ca3cc4b)

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.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.

None yet

4 participants