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-146092: Raise MemoryError on allocation failure in _zoneinfo by vstinner · Pull Request #146165 · python/cpython

Conversation

@vstinner

@vstinner vstinner commented Mar 19, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Member
  • Issue: Missing PyErr_NoMemory in _zoneinfo load_data and ts_to_local #146092

Sorry, something went wrong.

Uh oh!

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

All reactions
@vstinner
pythongh-146092: Raise MemoryError on allocation failure in _zoneinfo
5d51fa9
@vstinner
vstinner requested review from StanFromIreland and pganssle as code owners March 19, 2026 11:25
@vstinner vstinner added skip news needs backport to 3.13 only security fixes needs backport to 3.14 bugs and security fixes labels Mar 19, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Mar 19, 2026
Missing PyErr_NoMemory in _zoneinfo load_data and ts_to_local #146092
Closed
@bedevere-app bedevere-app Bot added the awaiting core review label Mar 19, 2026
kumaraditya303
kumaraditya303 approved these changes Mar 19, 2026
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Mar 19, 2026
StanFromIreland
StanFromIreland reviewed Mar 19, 2026
View reviewed changes

@StanFromIreland StanFromIreland 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.

Please also fix:

https://github.com/python/cpython/blob/main/Modules/_zoneinfo.c#L1872-L1875

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Modules/_zoneinfo.c Resolved

Uh oh!

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

@vstinner
Don't raise MemoryError in parse_transition_rule()
457b99f
@vstinner

vstinner commented Mar 19, 2026

Copy link
Copy Markdown
Member Author

Please also fix: https://github.com/python/cpython/blob/main/Modules/_zoneinfo.c#L1872-L1875

parse_transition_rule() is only used in parse_tz_str() and parse_tz_str() raises ValueError on parse_transition_rule() failure. Other parse_transition_rule() error paths don't set an exception. So I didn't add PyErr_NoMemory() in parse_transition_rule().

All reactions

Sorry, something went wrong.

Uh oh!

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

@StanFromIreland

StanFromIreland commented Mar 19, 2026

Copy link
Copy Markdown
Member

So I didn't add PyErr_NoMemory() in parse_transition_rule().

Can you please clarify why? The ValueError message may be misleading: "Malformed transition rule in TZ string"
I would update the check to only raise the ValueError if no other exception is already set.

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner

vstinner commented Mar 19, 2026

Copy link
Copy Markdown
Member Author

I would update the check to only raise the ValueError if no other exception is already set.

I tried that but I ended up with strange exceptions from a subfunction.

All reactions

Sorry, something went wrong.

Uh oh!

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

@StanFromIreland

StanFromIreland commented Mar 20, 2026

Copy link
Copy Markdown
Member

Oh yes, I see, I was able to reproduce that. Instead we could do:

         if (parse_transition_rule(&p, transitions[i])) {
-            PyErr_Format(PyExc_ValueError,
-                         "Malformed transition rule in TZ string: %R",
-                         tz_str_obj);
+            if (!PyErr_ExceptionMatches(PyExc_MemoryError)) {
+                PyErr_Format(PyExc_ValueError,
+                             "Malformed transition rule in TZ string: %R",
+                             tz_str_obj);
+            }
             goto error;
         }
     }

Since {day,calendar}rule_new (the subfunctions) only raise ValueErrors.

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner
Raise also MemoryError in parse_transition_rule()
e24c59c
@vstinner

vstinner commented Mar 20, 2026

Copy link
Copy Markdown
Member Author

Ok, I updated parse_transition_rule() to raise MemoryError and use if (!PyErr_ExceptionMatches(PyExc_MemoryError)) { in its caller.

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner

vstinner commented Mar 20, 2026

Copy link
Copy Markdown
Member Author

@StanFromIreland: Please review the updated PR.

All reactions

Sorry, something went wrong.

Uh oh!

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

StanFromIreland
StanFromIreland approved these changes Mar 20, 2026
View reviewed changes

@StanFromIreland StanFromIreland 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.

LGTM, thanks Victor!

Sorry, something went wrong.

Uh oh!

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

All reactions
@vstinner
vstinner merged commit 6450b1d into python:main Mar 20, 2026
48 checks passed

Uh oh!

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

@vstinner
vstinner deleted the zoneinfo_memoroyerror branch March 20, 2026 16:17
@miss-islington-app

miss-islington-app Bot commented Mar 20, 2026

Copy link
Copy Markdown

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app bedevere-app Bot removed the awaiting merge label Mar 20, 2026
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 20, 2026
@vstinner @miss-islington
pythongh-146092: Raise MemoryError on allocation failure in _zoneinfo (…
8403da2
…pythonGH-146165)

(cherry picked from commit 6450b1d)

Co-authored-by: Victor Stinner <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 20, 2026
@vstinner @miss-islington
pythongh-146092: Raise MemoryError on allocation failure in _zoneinfo (…
8025e78
…pythonGH-146165)

(cherry picked from commit 6450b1d)

Co-authored-by: Victor Stinner <[email protected]>
@bedevere-app

bedevere-app Bot commented Mar 20, 2026

Copy link
Copy Markdown

GH-146223 is a backport of this pull request to the 3.14 branch.

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Mar 20, 2026
@vstinner

vstinner commented Mar 20, 2026

Copy link
Copy Markdown
Member Author

Merged, thanks for your reviews!

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app

bedevere-app Bot commented Mar 20, 2026

Copy link
Copy Markdown

GH-146224 is a backport of this pull request to the 3.13 branch.

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 only security fixes label Mar 20, 2026
vstinner added a commit that referenced this pull request Mar 20, 2026
@miss-islington @vstinner
[3.13] gh-146092: Raise MemoryError on allocation failure in _zoneinfo (
cfd7f94
GH-146165) (#146224)

gh-146092: Raise MemoryError on allocation failure in _zoneinfo (GH-146165)
(cherry picked from commit 6450b1d)

Co-authored-by: Victor Stinner <[email protected]>
vstinner added a commit that referenced this pull request Mar 20, 2026
@miss-islington @vstinner
[3.14] gh-146092: Raise MemoryError on allocation failure in _zoneinfo (
a2a45d7
GH-146165) (#146223)

gh-146092: Raise MemoryError on allocation failure in _zoneinfo (GH-146165)
(cherry picked from commit 6450b1d)

Co-authored-by: Victor Stinner <[email protected]>
CuriousLearner added a commit to CuriousLearner/cpython that referenced this pull request Mar 22, 2026
@CuriousLearner
Merge remote-tracking branch 'upstream/main' into fix-pythongh-138577
2691ad9
* upstream/main: (1475 commits)
  Docs: replace all `datetime` imports with `import datetime as dt` (python#145640)
  pythongh-146153: Use `frozendict` in pure python fallback for `curses.has_key` (python#146154)
  pythongh-138234: clarify returncode behavior for subprocesses created with `shell=True` (python#138536)
  pythongh-140947: fix contextvars handling for server tasks in asyncio  (python#141158)
  pythonGH-100108: Add async generators best practices section (python#141885)
  pythonGH-145667: Merge `GET_ITER` and `GET_YIELD_FROM_ITER` (pythonGH-146120)
  pythongh-146228: Better fork support in cached FastPath (python#146231)
  pythongh-146227: Fix wrong type in _Py_atomic_load_uint16 in pyatomic_std.h (pythongh-146229)
  pythongh-145980: Fix copy/paste mistake in binascii.c (python#146230)
  pythongh-146092: Raise MemoryError on allocation failure in _zoneinfo (python#146165)
  pythongh-91279: Note `SOURCE_DATE_EPOCH` support in `ZipFile.writestr()` doc (python#139396)
  pythongh-146196: Fix Undefined Behavior in _PyUnicodeWriter_WriteASCIIString() (python#146201)
  pythongh-143930: Reject leading dashes in webbrowser URLs
  pythongh-145916: Soft-deprecate ctypes.util.find_library (pythonGH-145919)
  pythongh-146205: Check the errno with != 0 in close impls in select module (python#146206)
  pythongh-146171: Fix nested AttributeError suggestions (python#146188)
  pythongh-146099: Optimize _GUARD_CODE_VERSION+IP via function version symbols (pythonGH-146101)
  pythongh-145980: Add support for alternative alphabets in the binascii module (pythonGH-145981)
  pythongh-145754: Update signature retrieval in unittest.mock to use forwardref annotation format (python#145756)
  pythongh-145177: Add emscripten run --test, uses test args from config.toml (python#146160)
  ...
@pablogsal pablogsal mentioned this pull request Apr 4, 2026
gh-130273: Fix traceback color output with unicode characters #142529
Merged
ljfp pushed a commit to ljfp/cpython that referenced this pull request Apr 25, 2026
@vstinner @ljfp
pythongh-146092: Raise MemoryError on allocation failure in _zoneinfo (…
bd94f64
…python#146165)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@kumaraditya303 kumaraditya303 kumaraditya303 approved these changes
@StanFromIreland StanFromIreland StanFromIreland approved these changes
@pganssle pganssle Awaiting requested review from pganssle pganssle is a code owner

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

@vstinner @StanFromIreland @kumaraditya303
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.