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

ffi: fix segfault in _GET_TZINFO methods #2289

Merged
merged 1 commit into from
Apr 10, 2022

Conversation

davidhewitt
Copy link
Member

Looks like datetime types without tzinfo set will not have space allocated for the null pointer, so we should check has_tzinfo before trying to read it.

@davidhewitt davidhewitt mentioned this pull request Apr 10, 2022
Copy link
Member

@adamreichold adamreichold left a comment

Choose a reason for hiding this comment

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

The change looks good to me. I have to admit to feeling uneasy about ignoring the different struct layouts between PyDateTime_DateTime and PyDateTime_BaseDateTime. Is it ensured that we never write into a datetime that was allocated by someone else and might be missing that field? Maybe we could add a comment about this to the struct definition?

Copy link
Contributor

@pickfire pickfire left a comment

Choose a reason for hiding this comment

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

Looks good to me, just slightly worried we are not doing the cast like C.

@davidhewitt
Copy link
Member Author

davidhewitt commented Apr 10, 2022

From the datetime docs (https://docs.python.org/3/library/datetime.html#available-types):

Objects of these types are immutable.

I think it's a bug if we ever write to these things.

That said, I still agree we should be careful about the memory layout. I'll push the extra definitions in a follow-up PR.

@davidhewitt davidhewitt merged commit e6901e3 into PyO3:main Apr 10, 2022
@davidhewitt davidhewitt deleted the fix-get-tzinfo branch April 10, 2022 12:18
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