gh-145376: Fix refleak and null pointer deref in unusual error path of datetime module by eendebakpt · Pull Request #145476 · python/cpython · GitHub
Skip to content

gh-145376: Fix refleak and null pointer deref in unusual error path of datetime module - #145476

Merged
encukou merged 5 commits into
python:mainfrom
eendebakpt:refleak_datetime
Mar 5, 2026
Merged

encukou merged 5 commits into
python:mainfrom
eendebakpt:refleak_datetime

Conversation

@eendebakpt

@eendebakpt eendebakpt commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

@StanFromIreland StanFromIreland left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this should get a news entry.

@eendebakpt

Copy link
Copy Markdown
Contributor Author

@encukou

encukou commented Mar 4, 2026

Copy link
Copy Markdown
Member

I think we can skip [a news entry] since the changes are only in very rare paths.

That's my assesment too. It's technically a user-visible change, but that user needs to squint really hard.

Comment thread Modules/_datetimemodule.c Outdated
@@ -0,0 +1 @@
Fix refleak and null pointer deref in unusual error path of :mod:`datetime`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please remove it, users should not be impacted by this change. The error case is very unlikely.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I suggested adding it since this PR covers several cases increasing the likelyhood of one of them being hit. If you think it is better to remove it, I don't mind.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Usually, we don't document such fix for an unlikely corner case.

PyLong_FromLong() can only fail if the system has no more free memory.

datetime.datetime.astimezone() reads freed memory, but it only occurs if utcoffset() returns the wrong type. It seems like nobody reported the issue (with a reproducer), so it sounds unlikely to crash in practice (reading freed memory just works in the common case).

eendebakpt and others added 2 commits March 5, 2026 10:53
Co-authored-by: Victor Stinner <vstinner@python.org>
@encukou
encukou enabled auto-merge (squash) March 5, 2026 10:07
@encukou
encukou merged commit 0eaf260 into python:main Mar 5, 2026
49 checks passed
@bedevere-bot

Copy link
Copy Markdown

@eendebakpt
eendebakpt deleted the refleak_datetime branch March 19, 2026 21:39
ljfp pushed a commit to ljfp/cpython that referenced this pull request Apr 25, 2026
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.

6 participants