Skip to content

Fix a soundness bug with PyClassInitializer#4454

Merged
davidhewitt merged 1 commit intoPyO3:mainfrom
ChayimFriedman2:fix-unsound-pyclassinitializer
Aug 21, 2024
Merged

Fix a soundness bug with PyClassInitializer#4454
davidhewitt merged 1 commit intoPyO3:mainfrom
ChayimFriedman2:fix-unsound-pyclassinitializer

Conversation

@ChayimFriedman2
Copy link
Copy Markdown
Contributor

From now you cannot initialize a PyClassInitializer<SubClass> with PyClassInitializer::from(Py<BaseClass>).add_subclass(SubClass).

This was out of bounds write. Now it panics. See details at #4452.

This is a short-term fix for #4452.

Long-term, we probably want to forbid that at compile time, but that will be a breaking change.

Copy link
Copy Markdown
Member

@alex alex left a comment

Choose a reason for hiding this comment

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

This LGTM. We still have unsoundness because you can do PyClassInitializer::new(SubClass{}, PyClassInitializer::from(Py::new(py, Baseclass{}))) though :-(

Do you see a good way to deal with that? Maybe PyClassInitializer::new just shouldn't be public, is there a reason to use it?

Copy link
Copy Markdown
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

The ::new in particular is a bit strange given it's asking for inheritance, I would be ok with removing it (maybe by making it panic immediately for the Existing case and deprecating the symbol, to be at least a little graceful to users).

Comment thread tests/add_subclass_to_py.rs Outdated
@ChayimFriedman2 ChayimFriedman2 force-pushed the fix-unsound-pyclassinitializer branch from 1749f4c to fcecffb Compare August 19, 2024 14:13
@ChayimFriedman2
Copy link
Copy Markdown
Contributor Author

@alex Fixed the issue with new().

@ChayimFriedman2 ChayimFriedman2 force-pushed the fix-unsound-pyclassinitializer branch 3 times, most recently from 16abef4 to 2159f0f Compare August 19, 2024 22:25
From now you cannot initialize a `PyClassInitializer<SubClass>` with `PyClassInitializer::from(Py<BaseClass>).add_subclass(SubClass)`.

This was out of bounds write. Now it panics. See details at PyO3#4452.
@ChayimFriedman2 ChayimFriedman2 force-pushed the fix-unsound-pyclassinitializer branch from 2159f0f to 01edfde Compare August 19, 2024 23:24
Copy link
Copy Markdown
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Thanks!

@davidhewitt davidhewitt added this pull request to the merge queue Aug 21, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 21, 2024
@davidhewitt davidhewitt added this pull request to the merge queue Aug 21, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Aug 21, 2024
@ChayimFriedman2
Copy link
Copy Markdown
Contributor Author

I cannot reproduce valgrind's failure locally. @davidhewitt can you help with that?

@davidhewitt
Copy link
Copy Markdown
Member

See #4463, I pinned main back, this should merge ok now.

@davidhewitt davidhewitt added this pull request to the merge queue Aug 21, 2024
Merged via the queue into PyO3:main with commit 8413890 Aug 21, 2024
davidhewitt pushed a commit that referenced this pull request Sep 3, 2024
From now you cannot initialize a `PyClassInitializer<SubClass>` with `PyClassInitializer::from(Py<BaseClass>).add_subclass(SubClass)`.

This was out of bounds write. Now it panics. See details at #4452.
davidhewitt pushed a commit that referenced this pull request Sep 3, 2024
From now you cannot initialize a `PyClassInitializer<SubClass>` with `PyClassInitializer::from(Py<BaseClass>).add_subclass(SubClass)`.

This was out of bounds write. Now it panics. See details at #4452.
davidhewitt pushed a commit that referenced this pull request Sep 15, 2024
From now you cannot initialize a `PyClassInitializer<SubClass>` with `PyClassInitializer::from(Py<BaseClass>).add_subclass(SubClass)`.

This was out of bounds write. Now it panics. See details at #4452.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants