Skip to content

ffi: fix segfault in _GET_TZINFO methods#2289

Merged
davidhewitt merged 1 commit intoPyO3:mainfrom
davidhewitt:fix-get-tzinfo
Apr 10, 2022
Merged

ffi: fix segfault in _GET_TZINFO methods#2289
davidhewitt merged 1 commit intoPyO3:mainfrom
davidhewitt:fix-get-tzinfo

Conversation

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