GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-105375: Explicitly initialise all {Pickler,Unpickler}Object fields by erlend-aasland · Pull Request #105686 · python/cpython

Conversation

@erlend-aasland

@erlend-aasland erlend-aasland commented Jun 12, 2023 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

  • Issue: Incorrect error handling for APIs that can raise exceptions #105375

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@erlend-aasland
pythongh-105375: Explicitly initialise all {Pickler,Unpickler}Object …
eb0dd9b
…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.
@erlend-aasland erlend-aasland added skip news needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes labels Jun 12, 2023
@erlend-aasland
erlend-aasland requested a review from serhiy-storchaka June 12, 2023 10:37
@bedevere-bot bedevere-bot added the awaiting core review label Jun 12, 2023
@bedevere-bot bedevere-bot mentioned this pull request Jun 12, 2023
Incorrect error handling for APIs that can raise exceptions #105375
Closed
18 tasks done
@erlend-aasland erlend-aasland mentioned this pull request Jun 12, 2023
gh-105375: Improve _pickle error handling #105475
Merged
@erlend-aasland
Make object init cleaner:
e4fd637
- 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
serhiy-storchaka
serhiy-storchaka reviewed Jun 12, 2023
View reviewed changes

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this 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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@erlend-aasland

erlend-aasland commented Jun 12, 2023

Copy link
Copy Markdown
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 :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

serhiy-storchaka
serhiy-storchaka approved these changes Jun 12, 2023
View reviewed changes
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting core review labels Jun 12, 2023
@erlend-aasland
erlend-aasland merged commit ca3cc4b into python:main Jun 12, 2023
@miss-islington

miss-islington commented Jun 12, 2023

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the awaiting merge label Jun 12, 2023
@erlend-aasland
erlend-aasland deleted the fix-gh-105475 branch June 12, 2023 21:35
@miss-islington

miss-islington commented Jun 12, 2023

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington miss-islington assigned erlend-aasland Jun 12, 2023
@bedevere-bot

bedevere-bot commented Jun 12, 2023

Copy link
Copy Markdown

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 12, 2023
@erlend-aasland @miss-islington
pythongh-105375: Explicitly initialise all {Pickler,Unpickler}Object …
6bf9f44
…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 <[email protected]>
@bedevere-bot bedevere-bot removed the needs backport to 3.12 only security fixes label Jun 12, 2023
erlend-aasland added a commit to erlend-aasland/cpython that referenced this pull request Jun 12, 2023
@erlend-aasland
[3.11] pythongh-105375: Explicitly initialise all {Pickler,Unpickler}…
cba170e
…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 <[email protected]>
@bedevere-bot

bedevere-bot commented Jun 12, 2023

Copy link
Copy Markdown

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

erlend-aasland commented Jun 12, 2023

Copy link
Copy Markdown
Contributor Author

Thanks for the review!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

erlend-aasland added a commit that referenced this pull request Jun 12, 2023
@miss-islington @erlend-aasland
[3.12] gh-105375: Explicitly initialise all {Pickler,Unpickler}Object…
017b959
… 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 <[email protected]>
carljm added a commit to carljm/cpython that referenced this pull request Jun 12, 2023
@carljm
Merge branch 'main' into modulelocals
2fae889
* 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
@erlend-aasland
[3.11] gh-105375: Explicitly initialise all {Pickler,Unpickler}Object…
36c393c
… 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 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@serhiy-storchaka serhiy-storchaka serhiy-storchaka approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@erlend-aasland erlend-aasland

Labels

skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@erlend-aasland @miss-islington @bedevere-bot @serhiy-storchaka
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.