Skip to content

gh-116502: Fix memory access violation on fatal error with Windows #116503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dlaugt
Copy link

@dlaugt dlaugt commented Mar 8, 2024

Check if msg pointer is not null before calling strlen().

@ghost
Copy link

ghost commented Mar 8, 2024

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Mar 8, 2024

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@ericvsmith
Copy link
Member

Is NULL supposed to be valid value for fatal_output_debug()? If not, shouldn't the fix be to whatever is passing in NULL?

@dlaugt dlaugt requested a review from ZeroIntensity as a code owner June 20, 2025 19:17
@bedevere-app
Copy link

bedevere-app bot commented Jun 20, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@dlaugt dlaugt force-pushed the memory-violation-on-fatal-error-windows branch from 277b5a0 to f67eab6 Compare June 20, 2025 20:57
@bedevere-app
Copy link

bedevere-app bot commented Jun 20, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@dlaugt dlaugt force-pushed the memory-violation-on-fatal-error-windows branch from f67eab6 to 3f13c4e Compare June 20, 2025 20:58
@bedevere-app
Copy link

bedevere-app bot commented Jun 20, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@dlaugt dlaugt force-pushed the memory-violation-on-fatal-error-windows branch from 3f13c4e to c0e6be8 Compare June 20, 2025 21:08
Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

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

It's a nice catch because at L3307, we have this kind of if (msg) check.

I would advise adding an assert(msg != NULL) in fatal_output_debug though and add a comment for fatal_error saying that msg = NULL is allowed.

@dlaugt dlaugt force-pushed the memory-violation-on-fatal-error-windows branch from c0e6be8 to 5fdc099 Compare June 20, 2025 21:40
@dlaugt
Copy link
Author

dlaugt commented Jun 20, 2025

I've added the assert(msg != NULL) in fatal_output_debug.

@picnixz picnixz added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Jun 20, 2025
Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

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

Sorry to block, but I think this is the wrong fix. When fatal_error is called with a NULL message (via _Py_FatalErrorFormat), fatal_output_debug should not write the Fatal Python Error header, because the caller already wrote it. I think it makes more sense to not call fatal_output_debug at all if msg is NULL.

Two other things:

  1. This is definitely testable, we should test _Py_FatalErrorFormat in _testinternalcapi.
  2. I would have thought this needed a news entry, because this is a crash fix.

Bénédikt, what was your rationale behind skip news and no tests? I'm happy to defer if you have concerns about either.

@bedevere-app
Copy link

bedevere-app bot commented Jun 21, 2025

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@picnixz
Copy link
Member

picnixz commented Jun 21, 2025

Ah I forgot about the NEWS. Since the OP committed quite a lot, there was the bot notif and I added the label just to reduce the noise, but I forgot to add one.

As for the tests, sure we can add some! I may have missed the fact that the header was already written. However the function has already some if (msg) checks so we should also change them if needed.

@picnixz picnixz removed the skip news label Jun 21, 2025
@bedevere-app
Copy link

bedevere-app bot commented Jun 21, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@ZeroIntensity
Copy link
Member

I may have missed the fact that the header was already written. However the function has already some if (msg) checks so we should also change them if needed.

No worries, it's not particularly intuitive. fatal_error can do a bunch of different weird things. In this case, msg will only be NULL when header is 0, but fatal_output_debug unconditionally writes the header.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting changes needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants