GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-111178: fix UBSan failures in `Modules/_datetimemodule.c` by picnixz · Pull Request #129774 · python/cpython

Conversation

@picnixz

@picnixz picnixz commented Feb 7, 2025 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

This PR fixes the UBSan failures and addresses some minor cosmetic changes. PEP-7 changes were not applied since they could scramble the diff but other semantic changes affecting the signature of touched functions may have been done.

  • Issue: UBSan: Calling a function through pointer to incorrect function type is undefined behavior #111178

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
picnixz added 11 commits January 26, 2025 13:22
@picnixz
add cast macros for date and time objects
d4be207
@picnixz
fix UBSan failures for PyDateTime_Delta
6d1f263
@picnixz
fix UBSan failures for PyDateTime_Date
1aeeff8
@picnixz
fix UBSan failures for PyDateTime_TZInfo
9fee212
@picnixz
fix UBSan failures for PyDateTime_TimeZone
76d2c68
@picnixz
fix UBSan failures for PyDateTime_Time
25dbe38
@picnixz
fix UBSan failures for PyDateTime_DateTime
0a3cb0e
@picnixz
fix UBSan failures for PyDateTime_IsoCalendarDate
19bc7e1
@picnixz
use 'dummy' for NOARGS method
b189115
@picnixz
use 'dummy' for NOARGS method
3c883a6
@picnixz
Merge remote-tracking branch 'upstream/main' into fix/ubsan/datetime-…
86af79a
…111178
@picnixz picnixz added the skip news label Feb 7, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Feb 7, 2025
UBSan: Calling a function through pointer to incorrect function type is undefined behavior #111178
Closed
@picnixz
picnixz marked this pull request as ready for review February 7, 2025 18:07
@picnixz
picnixz requested review from abalkin and pganssle as code owners February 7, 2025 18:07
@bedevere-app bedevere-app Bot added the awaiting core review label Feb 7, 2025
picnixz
picnixz commented Feb 7, 2025
View reviewed changes
Comment thread Modules/_datetimemodule.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@picnixz
Fixup naming
22bdf8c
@picnixz

picnixz commented Feb 7, 2025

Copy link
Copy Markdown
Member Author

Ah I'm sorry I put this one as ready for review but I learned that _ + capital letter was also UB (#128248 (comment)) so I'll fix them tomorrow.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz
picnixz marked this pull request as draft February 7, 2025 18:31
@bedevere-app bedevere-app Bot removed the awaiting core review label Feb 7, 2025
picnixz added 2 commits February 8, 2025 09:52
@picnixz
Do not use _ + capital letter in new code as it is also UB.
b6ee734
@picnixz
Merge branch 'fix/ubsan/datetime-111178' of github.com:picnixz/cpytho…
9296eb6
…n into fix/ubsan/datetime-111178
@picnixz
picnixz marked this pull request as ready for review February 8, 2025 08:58
@bedevere-app bedevere-app Bot added the awaiting core review label Feb 8, 2025
chris-eibl
chris-eibl reviewed Feb 9, 2025
View reviewed changes

@chris-eibl chris-eibl left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Just nitpicks most probably related to mechanical changes.

At some places, the casts would not be needed and the PR could be kept smaller.

Most probably you'd still want the renamings like

time_utcoffset(PyObject *op, PyObject *Py_UNUSED(dummy))

for consistency with the rest of the PR, even though there and at some other places no change would be needed at all.

Tried to locate them, hopefully no false positives - need a break now :)

So just happily ignore where not appropriate.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Modules/_datetimemodule.c
static PyObject *
time_utcoffset(PyObject *self, PyObject *unused) {
time_utcoffset(PyObject *op, PyObject *Py_UNUSED(dummy)) {
PyDateTime_Time *self = PyTime_CAST(op);

@chris-eibl chris-eibl Feb 9, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Before the PR, time_utcoffset already got a PyObject as first parameter and GET_TIME_TZINFO happily accepts it.
Maybe omit the PyTime_CAST to keep the diff smaller?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Modules/_datetimemodule.c
static PyObject *
time_dst(PyObject *self, PyObject *unused) {
time_dst(PyObject *op, PyObject *Py_UNUSED(dummy)) {
PyDateTime_Time *self = PyTime_CAST(op);

@chris-eibl chris-eibl Feb 9, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Similar to above: maybe omit the PyTime_CAST to keep the diff smaller?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Modules/_datetimemodule.c
static PyObject *
time_tzname(PyDateTime_Time *self, PyObject *unused) {
time_tzname(PyObject *op, PyObject *Py_UNUSED(dummy)) {
PyDateTime_Time *self = PyTime_CAST(op);

@chris-eibl chris-eibl Feb 9, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Similar to above: maybe omit the PyTime_CAST to keep the diff smaller?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Modules/_datetimemodule.c
datetime_hour(PyDateTime_DateTime *self, void *unused)
datetime_hour(PyObject *op, void *Py_UNUSED(closure))
{
PyDateTime_DateTime *self = PyDateTime_CAST(op);

@chris-eibl chris-eibl Feb 9, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The DATE_GET_* macros would not need the PyDateTime_CAST.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Modules/_datetimemodule.c
datetime_minute(PyDateTime_DateTime *self, void *unused)
datetime_minute(PyObject *op, void *Py_UNUSED(closure))
{
PyDateTime_DateTime *self = PyDateTime_CAST(op);

@chris-eibl chris-eibl Feb 9, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The DATE_GET_* macros would not need the PyDateTime_CAST.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Modules/_datetimemodule.c
datetime_tzname(PyObject *self, PyObject *unused) {
return call_tzname(GET_DT_TZINFO(self), self);
datetime_tzname(PyObject *op, PyObject *Py_UNUSED(dummy)) {
PyDateTime_DateTime *self = PyDateTime_CAST(op);

@chris-eibl chris-eibl Feb 9, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Ditto.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Modules/_datetimemodule.c
datetime_microsecond(PyDateTime_DateTime *self, void *unused)
datetime_microsecond(PyObject *op, void *Py_UNUSED(closure))
{
PyDateTime_DateTime *self = PyDateTime_CAST(op);

@chris-eibl chris-eibl Feb 9, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The DATE_GET_* macros would not need the PyDateTime_CAST.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Modules/_datetimemodule.c
datetime_ctime(PyObject *op, PyObject *Py_UNUSED(dummy))
{
return format_ctime((PyDateTime_Date *)self,
PyDateTime_DateTime *self = PyDateTime_CAST(op);

@chris-eibl chris-eibl Feb 9, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The DATE_GET_* macros would not need the PyDateTime_CAST.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Modules/_datetimemodule.c
datetime_getdate(PyDateTime_DateTime *self, PyObject *Py_UNUSED(ignored))
datetime_getdate(PyObject *op, PyObject *Py_UNUSED(dummy))
{
PyDateTime_DateTime *self = PyDateTime_CAST(op);

@chris-eibl chris-eibl Feb 9, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The DATE_GET_* macros would not need the PyDateTime_CAST.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Modules/_datetimemodule.c
datetime_gettimetz(PyDateTime_DateTime *self, PyObject *Py_UNUSED(ignored))
datetime_gettimetz(PyObject *op, PyObject *Py_UNUSED(dummy))
{
PyDateTime_DateTime *self = PyDateTime_CAST(op);

@chris-eibl chris-eibl Feb 9, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The DATE_GET_* macros would not need the PyDateTime_CAST.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@picnixz

picnixz commented Feb 9, 2025

Copy link
Copy Markdown
Member Author

The reason why I made the changes here is because the macros may be extended to static inline functions with runtime checks in the future and we definitely don't want to fill out missing pieces. For now, they don't do anything but ideally, the GET_ macros should be using fast casts (no checks) while _CAST macros will be using real checks.

chris-eibl and encukou reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz

picnixz commented Feb 9, 2025

Copy link
Copy Markdown
Member Author

Ah! I remember what I did. I wrote a note saying that a postmerge task should be done where I eliminate the unnecessary casts in the GET macros so that we can add a check in the macro instead of in the getters.

chris-eibl reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@encukou
Merge in the main branch to resolve conflict with python#127345
f108a14
@encukou
encukou enabled auto-merge (squash) February 19, 2025 10:56
@encukou
encukou merged commit c637bce into python:main Feb 19, 2025
@bedevere-app bedevere-app Bot removed the awaiting core review label Feb 19, 2025
@picnixz
picnixz deleted the fix/ubsan/datetime-111178 branch February 21, 2025 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@chris-eibl chris-eibl chris-eibl left review comments
@pganssle pganssle Awaiting requested review from pganssle pganssle is a code owner
@abalkin abalkin Awaiting requested review from abalkin

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@picnixz @chris-eibl @encukou
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.