Skip to content

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

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

gh-145376: Fix refleak and null pointer deref in unusual error path of datetime module#145476
encukou merged 5 commits intopython:mainfrom
eendebakpt:refleak_datetime

Conversation

@eendebakpt
Copy link
Contributor

@eendebakpt eendebakpt commented Mar 3, 2026

Copy link
Member

@StanFromIreland StanFromIreland left a comment

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
Contributor Author

I think this should get a news entry.

Added the news entry, although I think we can skip it since the changes are only in very rare paths.

@encukou
Copy link
Member

encukou commented Mar 4, 2026

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.

@@ -0,0 +1 @@
Fix refleak and null pointer deref in unusual error path of :mod:`datetime`.
Copy link
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
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
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

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot ARM64 macOS 3.x (tier-2) has failed when building commit 0eaf260.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/725/builds/12928) and take a look at the build logs.
  4. Check if the failure is related to this commit (0eaf260) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/725/builds/12928

Failed tests:

  • test_urllib2net

Summary of the results of the build (if available):

==

Click to see traceback logs
remote: Enumerating objects: 4, done.        
remote: Counting objects:  25% (1/4)        
remote: Counting objects:  50% (2/4)        
remote: Counting objects:  75% (3/4)        
remote: Counting objects: 100% (4/4)        
remote: Counting objects: 100% (4/4), done.        
remote: Compressing objects:  25% (1/4)        
remote: Compressing objects:  50% (2/4)        
remote: Compressing objects:  75% (3/4)        
remote: Compressing objects: 100% (4/4)        
remote: Compressing objects: 100% (4/4), done.        
remote: Total 4 (delta 0), reused 1 (delta 0), pack-reused 0 (from 0)        
From https://github.com/python/cpython
 * branch                    main       -> FETCH_HEAD
Note: switching to '0eaf260d79f8547b02d8e80d760b11e821928fde'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 0eaf260d79f gh-145376: Fix refleak and null pointer deref in unusual error path of datetime module (GH-145476)
Switched to and reset branch 'main'

make: *** [buildbottest] Error 2

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