From 2cf6b2caade94e75f10363df6f432a3e6515be6c Mon Sep 17 00:00:00 2001 From: Ramin Farajpour Cami Date: Sat, 7 Mar 2026 17:01:45 +0330 Subject: [PATCH 1/2] gh-145623: Fix crashes on uninitialized struct.Struct objects (gh-145624) --- Lib/test/test_struct.py | 2 ++ .../Library/2026-03-07-15-00-00.gh-issue-145623.2Y7LzT.rst | 3 +++ Modules/_struct.c | 2 ++ 3 files changed, 7 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2026-03-07-15-00-00.gh-issue-145623.2Y7LzT.rst diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py index aa793a2c223de9..4cbfd7ad8b1e48 100644 --- a/Lib/test/test_struct.py +++ b/Lib/test/test_struct.py @@ -836,6 +836,8 @@ def test_operations_on_half_initialized_Struct(self): self.assertRaises(RuntimeError, S.unpack, spam) self.assertRaises(RuntimeError, S.unpack_from, spam) self.assertRaises(RuntimeError, getattr, S, 'format') + self.assertRaises(RuntimeError, S.__sizeof__) + self.assertRaises(RuntimeError, repr, S) self.assertEqual(S.size, -1) diff --git a/Misc/NEWS.d/next/Library/2026-03-07-15-00-00.gh-issue-145623.2Y7LzT.rst b/Misc/NEWS.d/next/Library/2026-03-07-15-00-00.gh-issue-145623.2Y7LzT.rst new file mode 100644 index 00000000000000..77b43e79e35860 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-03-07-15-00-00.gh-issue-145623.2Y7LzT.rst @@ -0,0 +1,3 @@ +Fix crash in :mod:`struct` when calling :func:`repr` or +``__sizeof__()`` on an uninitialized :class:`struct.Struct` +object created via ``Struct.__new__()`` without calling ``__init__()``. diff --git a/Modules/_struct.c b/Modules/_struct.c index ae8a8ffb3c005a..dcc3c7ec63e9e0 100644 --- a/Modules/_struct.c +++ b/Modules/_struct.c @@ -2382,6 +2382,7 @@ static PyObject * Struct___sizeof___impl(PyStructObject *self) /*[clinic end generated code: output=2d0d78900b4cdb4e input=faca5925c1f1ffd0]*/ { + ENSURE_STRUCT_IS_READY(self); size_t size = _PyObject_SIZE(Py_TYPE(self)) + sizeof(formatcode); for (formatcode *code = self->s_codes; code->fmtdef != NULL; code++) { size += sizeof(formatcode); @@ -2393,6 +2394,7 @@ static PyObject * s_repr(PyObject *op) { PyStructObject *self = PyStructObject_CAST(op); + ENSURE_STRUCT_IS_READY(self); PyObject* fmt = PyUnicode_FromStringAndSize( PyBytes_AS_STRING(self->s_format), PyBytes_GET_SIZE(self->s_format)); if (fmt == NULL) { From 149c4657507d17f78dd0938419a5a24ed71dc07e Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sat, 7 Mar 2026 16:53:13 +0200 Subject: [PATCH 2/2] Fix bug notifier for issues with no body text (#145603) --- .github/workflows/new-bugs-announce-notifier.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/new-bugs-announce-notifier.yml b/.github/workflows/new-bugs-announce-notifier.yml index b25750f0897de2..9ee38a4fd1cefc 100644 --- a/.github/workflows/new-bugs-announce-notifier.yml +++ b/.github/workflows/new-bugs-announce-notifier.yml @@ -44,7 +44,7 @@ jobs: // We need to truncate the body size, because the max size for // the whole payload is 16kb. We want to be safe and assume that // body can take up to ~8kb of space. - body : issue.data.body.substring(0, 8000) + body : (issue.data.body || "").substring(0, 8000) }; const data = {