Visitar URL original
gh-111306: Add explicit conversion from PyObject to datetime for find_ttinfo in _zoneinfo.c by Jason-Y-Z · Pull Request #111458 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20260624061212/https://github.com/python/cpython/pull/111458
Skip to content
/ cpython Public

gh-111306: Add explicit conversion from PyObject to datetime for find_ttinfo in _zoneinfo.c#111458

Closed
Jason-Y-Z wants to merge 1 commit into
python:mainfrom
Jason-Y-Z:fix-issue-111306
Closed

gh-111306: Add explicit conversion from PyObject to datetime for find_ttinfo in _zoneinfo.c#111458
Jason-Y-Z wants to merge 1 commit into
python:mainfrom
Jason-Y-Z:fix-issue-111306

Conversation

@Jason-Y-Z

@Jason-Y-Z Jason-Y-Z commented Oct 29, 2023 •

Copy link
Copy Markdown
Contributor

@wence- wence- left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks, although I am not completely sure this is the right approach:

  • There is still an unchecked access to year on line 2216 in find_ttinfo.
  • fold may still induce an out of bounds access since unlike when constructing a true datetime object, there is no bounds checking on a duck-typed datetime: after truncation to unsigned char it could have any value in [0, 256).
  • (This one is not specifically related the interpreter segfault) Unlike when constructing a true datetime object, a duck-typed datetime has no bounds checking of its properties.

So perhaps one should introduce an as_datetime helper that takes PyObject * and delivers a PyDateTime_DateTime *, and then narrow the input type of find_ttinfo to accept a PyDateTime_DateTime *. WDYT?

Comment thread Modules/_zoneinfo.c Outdated
@Jason-Y-Z

Copy link
Copy Markdown
Contributor Author

Thanks @wence- for the great idea, I had another attempt towards that direction

Comment thread Modules/_zoneinfo.c Outdated
Comment thread Modules/_zoneinfo.c Outdated
Comment thread Modules/_zoneinfo.c Outdated
Comment thread Modules/_zoneinfo.c
Comment thread Modules/_zoneinfo.c
@Jason-Y-Z Jason-Y-Z force-pushed the fix-issue-111306 branch 2 times, most recently from 83fb7b2 to 584b229 Compare October 31, 2023 13:51
@Jason-Y-Z Jason-Y-Z changed the title gh-111306: Improve getter function for datetime fold attribute gh-111306: Add explicit conversion from PyObject to datetime for find_ttinfo in _zoneinfo.c Oct 31, 2023
@Jason-Y-Z

Copy link
Copy Markdown
Contributor Author

@wence- sorry for asking but any thoughts on the latest version?

@wence- wence- left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think there is still a memory leak in the use of as_datetime. Additionally, the error-checking in as_datetime needs to be a bit tighter I think.

Comment thread Modules/_zoneinfo.c Outdated
Comment thread Modules/_zoneinfo.c
Comment thread Modules/_zoneinfo.c
@Jason-Y-Z Jason-Y-Z force-pushed the fix-issue-111306 branch 4 times, most recently from d7cbb4a to 7d93064 Compare February 10, 2024 22:11
@Jason-Y-Z Jason-Y-Z requested a review from wence- February 10, 2024 22:28
@Jason-Y-Z

Copy link
Copy Markdown
Contributor Author

I've hopefully addressed the issues. Would you mind taking a quick look again please? @wence- (I'm guessing News is not needed for this change? Happy to add one if useful!)

@wence- wence- left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks, some (non-blocking) suggestions that might be an improvement. I am not sure if my reviewing has any power here, but to the best of my understanding this looks correct.

The only missing open question I think is that the new as_local_timestamp function doesn't have any handling for the tzinfo slot, but I don't know if this is problematic.

Comment thread Modules/_zoneinfo.c
Comment thread Modules/_zoneinfo.c
@Jason-Y-Z Jason-Y-Z force-pushed the fix-issue-111306 branch 3 times, most recently from e445c03 to baeed62 Compare February 19, 2024 22:18
@Jason-Y-Z

Copy link
Copy Markdown
Contributor Author

Hey @pganssle @abalkin, sorry for tagging but since this is potentially datetime related, so I thought you might be interested.

@Jason-Y-Z Jason-Y-Z closed this Aug 3, 2024
@Jason-Y-Z Jason-Y-Z deleted the fix-issue-111306 branch August 3, 2024 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants