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

Inconsistent holder types cause crash #2052

Closed
wants to merge 2 commits into from

Conversation

rhaschke
Copy link
Contributor

@rhaschke rhaschke commented Jan 2, 2020

Currently, pybind11 doesn't check for compatibility of holder types. A holder caster accesses the corresponding value_and_holder slot without any type checking, which can cause serious crashes if the actually requested holder type doesn't match the declared one.
The first commit of this PR illustrates the issue as a new test case and the second commit suggests a potential solution: namely storing the typeinfo of the declared holder and comparing it to the requested one.
The failing tests emphasize another issue: there is no dynamic type casting for holders yet.

@rhaschke
Copy link
Contributor Author

rhaschke commented Jan 2, 2020

Alternatively, one could validate the compatibility of holder types in the constructor of the caster.

@rhaschke
Copy link
Contributor Author

Rebased onto master.

@rhaschke
Copy link
Contributor Author

Closing in favor of #1161, which checks only once during the definition of a new wrapper function, while my code checked for each cast.

@rhaschke rhaschke closed this Oct 20, 2020
@rhaschke rhaschke deleted the inconsistent-holder-types branch November 11, 2020 21:33
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.

1 participant